From 157924514877b470b7e7bc10a789ffb54441fd1f Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 8 Feb 2019 17:36:32 +0000 Subject: Update for older arXiv urls --- arxiv2remarkable.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'arxiv2remarkable.py') diff --git a/arxiv2remarkable.py b/arxiv2remarkable.py index 8c7b0ea..bd62776 100755 --- a/arxiv2remarkable.py +++ b/arxiv2remarkable.py @@ -63,17 +63,17 @@ def validate_url(url): False """ m = re.match( - "https?://arxiv.org/(abs|pdf)/\d{4}\.\d{5}(v\d+)?(\.pdf)?", url + "https?://arxiv.org/(abs|pdf)/\d{4}\.\d{4,5}(v\d+)?(\.pdf)?", url ) return not m is None def get_urls(url): """Get the pdf and abs url from any given url """ - if re.match("https?://arxiv.org/abs/\d{4}\.\d{5}(v\d+)?", url): + if re.match("https?://arxiv.org/abs/\d{4}\.\d{4,5}(v\d+)?", url): abs_url = url pdf_url = url.replace("abs", "pdf") + ".pdf" - elif re.match("https?://arxiv.org/pdf/\d{4}\.\d{5}(v\d+)?\.pdf", url): + elif re.match("https?://arxiv.org/pdf/\d{4}\.\d{4,5}(v\d+)?\.pdf", url): abs_url = url[:-4].replace("pdf", "abs") pdf_url = url else: -- cgit v1.2.3 From 59088c0a3a1b301dd57f4555d9dfbdc96bcc9515 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 8 Feb 2019 17:36:37 +0000 Subject: Formatting --- arxiv2remarkable.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'arxiv2remarkable.py') diff --git a/arxiv2remarkable.py b/arxiv2remarkable.py index bd62776..7a2f144 100755 --- a/arxiv2remarkable.py +++ b/arxiv2remarkable.py @@ -193,7 +193,8 @@ def get_paper_info(url): page = get_page_with_retry(url) soup = bs4.BeautifulSoup(page, "html.parser") authors = [ - x["content"] for x in soup.find_all("meta", {"name": "citation_author"}) + x["content"] + for x in soup.find_all("meta", {"name": "citation_author"}) ] title = soup.find_all("meta", {"name": "citation_title"})[0]["content"] date = soup.find_all("meta", {"name": "citation_date"})[0]["content"] @@ -215,7 +216,8 @@ def generate_filename(info): def upload_to_rm(filepath, remarkable_dir="/", rmapi_path="rmapi"): logger.info("Starting upload to reMarkable") status = subprocess.call( - [rmapi_path, "put", filepath, remarkable_dir], stdout=subprocess.DEVNULL + [rmapi_path, "put", filepath, remarkable_dir], + stdout=subprocess.DEVNULL, ) if not status == 0: exception("Uploading file %s to remarkable failed" % filepath) -- cgit v1.2.3 From cc3bceb78a94f4c8377468ed585bff93b71bada0 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Fri, 8 Feb 2019 17:39:58 +0000 Subject: Also update dearxiv function for older papers --- arxiv2remarkable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'arxiv2remarkable.py') diff --git a/arxiv2remarkable.py b/arxiv2remarkable.py index 7a2f144..6bb88fc 100755 --- a/arxiv2remarkable.py +++ b/arxiv2remarkable.py @@ -123,13 +123,13 @@ def dearxiv(input_file, pdftk_path="pdftk"): data = fid.read() # Remove the text element data = re.sub( - b"\(arXiv:\d{4}\.\d{5}v\d\s+\[\w+\.\w+\]\s+\d{1,2}\s\w{3}\s\d{4}\)Tj", + b"\(arXiv:\d{4}\.\d{4,5}v\d\s+\[\w+\.\w+\]\s+\d{1,2}\s\w{3}\s\d{4}\)Tj", b"()Tj", data, ) # Remove the URL element data = re.sub( - b"<<\\n\/URI \(http://arxiv\.org/abs/\d{4}\.\d{5}v\d\)\\n\/S /URI\\n>>\\n", + b"<<\\n\/URI \(http://arxiv\.org/abs/\d{4}\.\d{4,5}v\d\)\\n\/S /URI\\n>>\\n", b"", data, ) -- cgit v1.2.3 From 9ce1b9090dc151f31fbb3e9d1b62e1e4f6b75efc Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Tue, 12 Feb 2019 12:08:47 +0000 Subject: Add CLI flag to specify the destination directory on rM --- arxiv2remarkable.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'arxiv2remarkable.py') diff --git a/arxiv2remarkable.py b/arxiv2remarkable.py index 6bb88fc..b09bace 100755 --- a/arxiv2remarkable.py +++ b/arxiv2remarkable.py @@ -215,12 +215,18 @@ def generate_filename(info): def upload_to_rm(filepath, remarkable_dir="/", rmapi_path="rmapi"): logger.info("Starting upload to reMarkable") + if not remarkable_dir == "/": + status = subprocess.call([rmapi_path, "mkdir", remarkable_dir]) + if not status == 0: + exception( + "Creating directory %s on reMarkable failed" % remarkable_dir + ) status = subprocess.call( [rmapi_path, "put", filepath, remarkable_dir], stdout=subprocess.DEVNULL, ) if not status == 0: - exception("Uploading file %s to remarkable failed" % filepath) + exception("Uploading file %s to reMarkable failed" % filepath) logger.info("Upload successful.") @@ -243,6 +249,13 @@ def parse_args(): help="debug mode, doesn't upload to reMarkable", action="store_true", ) + parser.add_argument( + "-p", + "--remarkable-path", + help="directory on reMarkable to put the file (created if missing)", + dest="remarkable_dir", + default="/", + ) parser.add_argument( "--rmapi", help="path to rmapi executable", default="rmapi" ) @@ -302,7 +315,11 @@ def main(): else: shutil.move(clean_filename, start_wd) else: - upload_to_rm(clean_filename, rmapi_path=args.rmapi) + upload_to_rm( + clean_filename, + remarkable_dir=args.remarkable_dir, + rmapi_path=args.rmapi, + ) if __name__ == "__main__": -- cgit v1.2.3 From d34f7af05e95bdd8857aab7c6bf62f4c937a85fe Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Thu, 14 Feb 2019 10:43:49 +0000 Subject: Bugfix for directory creation rMapi was failing when the target directory had a trailing "/", so we always strip that now. --- arxiv2remarkable.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'arxiv2remarkable.py') diff --git a/arxiv2remarkable.py b/arxiv2remarkable.py index b09bace..2f7ffe1 100755 --- a/arxiv2remarkable.py +++ b/arxiv2remarkable.py @@ -214,15 +214,18 @@ def generate_filename(info): def upload_to_rm(filepath, remarkable_dir="/", rmapi_path="rmapi"): + remarkable_dir = remarkable_dir.rstrip("/") logger.info("Starting upload to reMarkable") - if not remarkable_dir == "/": - status = subprocess.call([rmapi_path, "mkdir", remarkable_dir]) + if remarkable_dir: + status = subprocess.call( + [rmapi_path, "mkdir", remarkable_dir], stdout=subprocess.DEVNULL + ) if not status == 0: exception( "Creating directory %s on reMarkable failed" % remarkable_dir ) status = subprocess.call( - [rmapi_path, "put", filepath, remarkable_dir], + [rmapi_path, "put", filepath, remarkable_dir + "/"], stdout=subprocess.DEVNULL, ) if not status == 0: -- cgit v1.2.3