summaryrefslogtreecommitdiffstats
path: root/build.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2015-02-28 20:09:43 -0500
committerThibaut Horel <thibaut.horel@gmail.com>2015-02-28 20:09:43 -0500
commit683cc893b0ec029e5b019e936e9c83c5c6798dac (patch)
tree64a9a5ddce2324fb4a45ba3b17fcbe745030afe5 /build.py
downloadreading_group-683cc893b0ec029e5b019e936e9c83c5c6798dac.tar.gz
Initial commit
Diffstat (limited to 'build.py')
-rw-r--r--build.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/build.py b/build.py
new file mode 100644
index 0000000..447d07b
--- /dev/null
+++ b/build.py
@@ -0,0 +1,53 @@
+from jinja2 import Template
+import csv
+from datetime import date
+import os.path as op
+import os
+from subprocess import check_output
+from itertools import chain
+from bs4 import BeautifulSoup
+
+
+def get_references(sessions):
+ keys = chain.from_iterable(session["refs"] for session in sessions)
+ with open("keys.txt", "w") as fh:
+ fh.write("\n".join(keys))
+ html_refs = check_output(["bibtex2html -nodoc -nobibsource -noheader -q "
+ "-o - -unicode -nokeys -a -citefile keys.txt "
+ "-s abbrv sub.bib"], shell=True)
+ os.remove("keys.txt")
+ body = BeautifulSoup(html_refs, "lxml").body
+ body.name = "ol"
+ body.hr.decompose()
+ entries = body.find_all("p")
+ entries[-1].decompose()
+ entries = entries[:-1]
+ keys = {}
+ for i, entry in enumerate(entries):
+ entry.name = "li"
+ entry["id"] = entry.a["name"]
+ entry.a.decompose()
+ keys[entry["id"]] = i + 1
+ return unicode(body), keys
+
+
+def clean(session):
+ month, day = map(int, session["date"].split("/"))
+ session_date = date(2015, month, day)
+ session["date"] = session_date.strftime("%a %m/%d")
+ session["refs"] = session["refs"].split(",")
+ fname = op.join("notes", session_date.strftime("%m-%d.pdf"))
+ if op.isfile(fname):
+ session["notes"] = fname
+ return session
+
+
+def build(sessions, refs, keys):
+ template = Template(open("index.jinja").read().decode("utf8"))
+ with open("index.html", "w") as fh:
+ fh.write(template.render(sessions=sessions,
+ refs=refs, keys=keys).encode("utf8"))
+
+sessions = [clean(session) for session in csv.DictReader(open("sessions.csv"))]
+refs, keys = get_references(sessions)
+build(sessions, refs, keys)