-
Notifications
You must be signed in to change notification settings - Fork 1
/
generatenice.py
61 lines (46 loc) · 1.83 KB
/
generatenice.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
55
56
57
58
59
60
# DEPRECATED. DO NOT USE. LEAVING THIS HERE JUST IN CASE PEOPLE FIND IT USEFUL SOMEHOW
# AS IT IS LESS COMPLICATED THAN generatenicelda.py
# creates the nice .html page
# assumes that pdftowordcloud.py, pdftothumbs.py and scrape.py were already run
import cPickle as pickle
# load the pickle of papers scraped from the HTML page (result of scrape.py)
paperdict = pickle.load(open( "papers.p", "rb" ))
print "Loaded %d papers from papers.p (generated by scrape.py)" % (len(paperdict), )
# load the top word frequencies (result of pdftowordcloud.py)
topdict = pickle.load(open("topwords.p", "rb"))
print "Loaded %d entries from topwords.p (generated by pdftowordcloud.py)" % (len(topdict), )
# build up the string
html = open("nipsnice_template.html", "r").read()
s = ""
for p in paperdict:
# get title, author
title, author = paperdict[p]
# get top words
topwords = topdict.get(p, [])
t = [x[0] for x in topwords]
tcat = ", ".join(t)
# get path to thumbnails for this paper
thumbpath = "thumbs/NIPS2012_%s.pdf.jpg" % (p, )
# get links to PDF, supplementary and bibtex on NIPS servers
pdflink = "http://books.nips.cc/papers/files/nips25/NIPS2012_%s.pdf" % (p, )
bibtexlink = "http://books.nips.cc/papers/files/nips25/bibhtml/NIPS2012_%s.html" % (p, )
supplink = "http://books.nips.cc/papers/files/nips25/NIPS2012_%s.extra.zip" % (p, )
s += """
<div class="apaper">
<div class="paperdesc">
<span class="ts">%s</span><br />
<span class="as">%s</span><br /><br />
</div>
<div class="dllinks">
<a href="%s">[pdf] </a>
<a href="%s">[bibtex] </a>
<a href="%s">[supplementary]<br /></a>
</div>
<img src = "%s"><br />
<span class="tt">TOP 100 words: %s</span>
</div>
""" % (title, author, pdflink, bibtexlink, supplink, thumbpath, tcat)
newhtml = html.replace("RESULTTABLE", s)
f = open("nipsnice.html", "w")
f.write(newhtml)
f.close()