Skip to content

Instantly share code, notes, and snippets.

@andrewyates
Last active March 29, 2018 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewyates/761089a1f5b9b71a255de0e920ce5f2e to your computer and use it in GitHub Desktop.
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
#!/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