-
Notifications
You must be signed in to change notification settings - Fork 0
/
arxiv2kindle.py
52 lines (40 loc) · 1.22 KB
/
arxiv2kindle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
To generate a kindle friendly html file from the current arxiv RSS
usage: arxiv2kindle.py [subject]
input:
[subject] is the subject category you want to browser, e.g., cs, math, astro-ph ...
can also be sub-category like astro-ph.CO, astro-ph.GA...
defaults to astro-ph
output:
[subject][date].html
Pre-requisite python packages: feedparser, html
Jiaxin Han, 27/05/2013
Durham
"""
import feedparser as f
from html import HTML
import sys
subject='astro-ph'
if len(sys.argv)>1:
subject=sys.argv[1]
def format_title(paper):
s='<b>'+paper['title'][:paper['title'].index('(arXiv:')]+'</b>'
id=paper['title'][paper['title'].index('(arXiv:')+7:-1]
s+='<a href='+paper['link']+'>'+id+'</a>'
return s
data=f.parse('http://export.arxiv.org/rss/'+subject)
out=HTML('html')
h=out.head()
t=h.title(data['feed']['title'])
t.text(data['feed']['updated'][:10])
body=out.body()
body.h1(subject+' '+data['feed']['updated'][:10]+', '+str(len(data['entries']))+' submissions')
l=body.ol
for paper in data['entries']:
li=l.li
li.text(format_title(paper),escape=False)
li.p(paper['author'],escape=False)
li.p(paper['summary'],escape=False)
outfile=file(subject+data['feed']['updated'][:10]+'.html','w')
outfile.write(str(out))
outfile.close()