diff --git a/olsync/olbrowserlogin.py b/olsync/olbrowserlogin.py index f5a8e9a..1a9eb30 100644 --- a/olsync/olbrowserlogin.py +++ b/olsync/olbrowserlogin.py @@ -17,6 +17,8 @@ # Where to get the CSRF Token and where to send the login request to LOGIN_URL = "https://www.overleaf.com/login" PROJECT_URL = "https://www.overleaf.com/project" # The dashboard URL +# JS snippet to get the first link +JAVASCRIPT_EXTRACT_PROJECT_URL = "document.getElementsByClassName('dash-cell-name')[1].firstChild.href" # JS snippet to extract the csrfToken JAVASCRIPT_CSRF_EXTRACTOR = "document.getElementsByName('ol-csrfToken')[0].content" # Name of the cookies we want to extract @@ -55,13 +57,22 @@ def __init__(self, *args, **kwargs): def handle_load_finished(self): def callback(result): - self._csrf = result - self._login_success = True - QCoreApplication.quit() + + def callback(result): + self._csrf = result + self._login_success = True + QCoreApplication.quit() + + self.webview.load(QUrl.fromUserInput(result)) + self.webview.loadFinished.connect( lambda x: + self.webview.page().runJavaScript( + JAVASCRIPT_CSRF_EXTRACTOR, 0, callback + ) + ) if self.webview.url().toString() == PROJECT_URL: self.webview.page().runJavaScript( - JAVASCRIPT_CSRF_EXTRACTOR, 0, callback + JAVASCRIPT_EXTRACT_PROJECT_URL, 0, callback ) def handle_cookie_added(self, cookie): diff --git a/olsync/olclient.py b/olsync/olclient.py index a993de1..fdbd701 100644 --- a/olsync/olclient.py +++ b/olsync/olclient.py @@ -15,6 +15,7 @@ import uuid from socketIO_client import SocketIO import time +import re # Where to get the CSRF Token and where to send the login request to LOGIN_URL = "https://www.overleaf.com/login" @@ -89,8 +90,8 @@ def all_projects(self): """ projects_page = reqs.get(PROJECT_URL, cookies=self._cookie) json_content = json.loads( - BeautifulSoup(projects_page.content, 'html.parser').find('meta', {'name': 'ol-projects'}).get('content')) - return list(OverleafClient.filter_projects(json_content)) + BeautifulSoup(projects_page.content, 'html.parser').find("meta", {"content": re.compile('\{.*"projects".*\}')}).get('content')) + return list(OverleafClient.filter_projects(json_content['projects'])) def get_project(self, project_name): """ @@ -101,8 +102,8 @@ def get_project(self, project_name): projects_page = reqs.get(PROJECT_URL, cookies=self._cookie) json_content = json.loads( - BeautifulSoup(projects_page.content, 'html.parser').find('meta', {'name': 'ol-projects'}).get('content')) - return next(OverleafClient.filter_projects(json_content, {"name": project_name}), None) + BeautifulSoup(projects_page.content, 'html.parser').find("meta", {"content": re.compile('\{.*"projects".*\}')}).get('content')) + return next(OverleafClient.filter_projects(json_content['projects'], {"name": project_name}), None) def download_project(self, project_id): """ @@ -233,6 +234,7 @@ def upload_file(self, project_id, project_infos, file_name, file_size, file): "qqtotalfilesize": file_size, } files = { + 'name': (None, file_name), "qqfile": file } diff --git a/olsync/olsync.py b/olsync/olsync.py index 56c5f9e..739492c 100644 --- a/olsync/olsync.py +++ b/olsync/olsync.py @@ -83,6 +83,11 @@ def main(ctx, local, remote, project_name, cookie_path, sync_path, olignore_path "Project downloaded successfully.", "Project could not be downloaded.", verbose) + + if not os.path.isfile(olignore_path): + click.echo("\nNotice: .olignore file does not exist, will sync all items.") + else: + click.echo("\n.olignore: using %s to filter items" % olignore_path) sync = not (local or remote) @@ -186,7 +191,8 @@ def download_project_pdf(): open(file_name, 'wb').write(content) return True - + + click.echo("="*40) if not os.path.isfile(cookie_path): raise click.ClickException( "Persisted Overleaf cookie not found. Please login or check store path.") @@ -369,12 +375,12 @@ def olignore_keep_list(olignore_path): # get list of files recursively (ignore .* files) files = glob.glob('**', recursive=True) - click.echo("="*40) + # click.echo("="*40) if not os.path.isfile(olignore_path): - click.echo("\nNotice: .olignore file does not exist, will sync all items.") + # click.echo("\nNotice: .olignore file does not exist, will sync all items.") keep_list = files else: - click.echo("\n.olignore: using %s to filter items" % olignore_path) + # click.echo("\n.olignore: using %s to filter items" % olignore_path) with open(olignore_path, 'r') as f: ignore_pattern = f.read().splitlines()