import os, sys, getopt, re
+import dateutil.parser
def format_latex(text):
def entryDateSortKey(p):
k, e = p
+ if 'date' in e.fields:
+ return e.fields['date']
+
month2num = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \
'apr' : '04', 'may' : '05', 'jun' : '06', \
'jul' : '07', 'aug' : '08', 'sep' : '09', \
return e.fields['year'] + "-" + month
+def entryGetYear(e):
+ if 'year' in e.fields:
+ return e.fields['year']
+
+ if 'date' in e.fields:
+ dt = dateutil.parser.isoparse(e.fields['date'])
+ return str(dt.year)
+
+ return None
+
+
def usage():
"""Print usage text of this program"""
bib_data = parser.parse_file(bibfile)
entries = bib_data.entries
- years = list(set([ b.fields['year'] for b in entries.values() ]))
+ years = list(set([entryGetYear(e) for e in entries.values()]))
years.sort(reverse=True)
for year in years:
iteritems.sort(key=entryDateSortKey, reverse=True)
for key, entry in iteritems:
- if entry.fields['year'] != year:
+ if entryGetYear(entry) != year:
continue
print("<div class=bibentry>")