forked from c4dm/c4dmpoole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.py
59 lines (50 loc) · 2.28 KB
/
macros.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
import csv, glob, json
from operator import itemgetter
def twitter():
return """<a href="#aftertw" id="skiptw">Skip tweets</a><a class="twitter-timeline" href="https://twitter.com/c4dm" data-widget-id="561187870955040769" data-chrome="nofooter" width="300" height="900">Tweets by @c4dm</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script><br /><a name="aftertw" id="aftertw"></a>"""
def peoplelist(criteria=None):
if criteria==None:
criteria = {}
ret = "<table width='100%' class='peoplelist'>"
ret += "\n <tr><th>Name</th><th>Project/interests/keywords</th></tr>"
peopledata = {}
for fpath in glob.glob("input/people_data/*.json"):
with open(fpath, 'rb') as jsonfp:
try:
aperson = json.load(jsonfp)
aperson['sortkey'] = aperson['name'].strip().split(' ')[-1]
for atheme in aperson['themes']:
aperson['theme_%s' % atheme] = '1'
peopledata[aperson['name']] = aperson
except:
print("WARNING: error parsing file %s" % fpath)
pass
for x in sorted(peopledata.values(), key=itemgetter('sortkey')):
if any([x.get(key, '') != val for key, val in criteria.items()]):
continue
if x.get('url', '') != '':
htmlname = "<a href='%s'>%s</a>" % (x['url'], x.get('name'))
else:
htmlname = x.get('name')
if x.get('acadposition', '') != '':
htmlname += "<br />%s" % (x.get('acadposition'))
blurb = x.get('blurb', '')
if blurb in [None, 'None', '*']:
blurb = ''
ret += "\n <tr><td>%s</td><td>%s</td></tr>" % (htmlname, blurb)
ret += "</table>"
return ret
def publicationslist(year):
ret = """<p>Select year: <strong>%i</strong>""" % year
for otheryear in range(year-1, 1995, -1):
ret += " <a href='pubs%i.html'>%i</a>" % (otheryear, otheryear)
ret +="""
<h2>%i</h2>""" % year
# Now load the content pre-rendered by bibtex2html
with open("input/pubs%i_raw.html" % year, "r") as fp:
data = ''.join(fp.readlines())
ret += data
return ret
def pagesourceurl():
#return "https://github.com/c4dm/c4dmpoole/tree/master/%s" % (str(page))
return "https://github.com/c4dm/c4dmpoole/edit/master/%s" % (str(page))