-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharxiv2kindle_LT.py
57 lines (45 loc) · 1.29 KB
/
arxiv2kindle_LT.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
50
51
52
53
54
"""
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 (no html requirement)
Jiaxin Han, 27/05/2013
Durham
"""
import feedparser as f
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)
date=data['feed']['updated'][:10]
o=file(subject+date+'.html','w')
o.write('<html>\n')
o.write('<head>\n')
o.write('<title>')
o.write(data['feed']['title'])
o.write(' '+date)
o.write('</title>\n')
o.write('</head>\n')
o.write('<body>\n')
o.write('<h1>'+subject+' '+date+', '+str(len(data['entries']))+' submissions </h1>')
o.write('<ol>\n')
for paper in data['entries']:
o.write('<li>\n')
o.write(format_title(paper))
o.write('<p>'+paper['author']+'</p>')
o.write(paper['summary'])
o.write('</li>\n')
o.write('</body>\n')
o.write('</html>')
o.close()