Last active
March 29, 2018 09:08
-
-
Save andrewyates/761089a1f5b9b71a255de0e920ce5f2e to your computer and use it in GitHub Desktop.
Downloads arxiv papers and adds them to reMarkable's cloud storage. Requires https://github.com/lukasschwab/arxiv.py and https://github.com/juruen/rmapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
from subprocess import Popen, PIPE | |
import arxiv | |
def download_paper(url, outdir="/home/andrew/.arxiv/"): | |
if not os.path.exists(outdir): | |
os.makedirs(outdir) | |
if url.endswith('.pdf'): | |
url = url[:-4] | |
uid = url.split('/')[-1] | |
print(uid, url) | |
r = arxiv.query(id_list=[uid]) | |
assert len(r) == 1 | |
fn = ''.join(c for c in r[0]['title'] if c.isalnum() or c in [' ', ',', ':', ';', '?', '-']) | |
print(fn) | |
paper = {'pdf_url': r[0]['pdf_url'], 'title': fn} | |
arxiv.download(paper, dirname=outdir) | |
outfn = os.path.join(outdir, fn + ".pdf") | |
return outfn | |
def add_paper(url): | |
fn = download_paper(url) | |
p = Popen(["/home/andrew/go/bin/rmapi", "put", fn]) | |
output, stderr = p.communicate() | |
print(output) | |
print(stderr) | |
print(p.returncode, "\n\n") | |
if __name__ == '__main__': | |
for url in sys.argv[1:]: | |
add_paper(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment