X-Git-Url: http://git.sthu.org/?a=blobdiff_plain;f=bib2html.py;h=72a57718d7ab96976e315531b5774b74d7d37dae;hb=b833cf05a90761d75477120640eef90a38833a6a;hp=111d1085db02106616cfcf92011846fab8c2f0f6;hpb=30117934eddd457d8abef2cb0ed11c48e2de71d9;p=shutils.git diff --git a/bib2html.py b/bib2html.py index 111d108..72a5771 100755 --- a/bib2html.py +++ b/bib2html.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """Creates a webpage with all entries of a .bib file""" -__version__ = "1.0" +__version__ = "1.1" __author__ = "Stefan Huber" __email__ = "shuber@sthu.org" @@ -31,11 +31,13 @@ __license__ = "MIT" # OTHER DEALINGS IN THE SOFTWARE. -import os, sys, getopt +import os, sys, getopt, re def format_latex(text): - return text.replace('{', '').replace('}', '').replace('\\', '') + # Get rid of matching dollar signs + text = re.sub(r'\$([^\$]*)\$', r'\1', text) + return text.replace('\mathcal', '').replace('{', '').replace('}', '').replace('\\', '') def format_field_span(type, value): return "" + format_latex(value) + "" @@ -47,7 +49,7 @@ def format_field(bibentry, field, pre='', post=''): return "" def format_author(a): - return ' '.join(' '.join(p) for p in (a.first(), a.middle(), a.prelast(), a.last(), a.lineage()) if p) + return ' '.join(' '.join(p) for p in (a.first_names, a.middle_names, a.prelast_names, a.last_names, a.lineage_names) if p) def format_authors(entry): return ", ".join([format_author(a) for a in entry.persons['author']]) @@ -127,24 +129,24 @@ def format_entry(entry): return "
\n".join(lines) -def entryCompareDate(p1, p2): - k1, e1 = p1 - k2, e2 = p2 +def entryDateSortKey(p): + k, e = p + month2num = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \ + 'apr' : '04', 'may' : '05', 'jun' : '06', \ + 'jul' : '07', 'aug' : '08', 'sep' : '09', \ + 'oct' : '10', 'nov' : '11', 'dec' : '12'} - def toStr(e): - month2num = { 'jan' : '01', 'feb' : '02', 'mar' : '03', \ - 'apr' : '04', 'may' : '05', 'jun' : '06', \ - 'jul' : '07', 'aug' : '08', 'sep' : '09', \ - 'oct' : '10', 'nov' : '11', 'dec' : '12'} - month = e.fields['month'].lower()[0:3] - if month in month2num: - month = month2num[month] - else: - month = "" - return e.fields['year'] + "-" + month + if not 'month' in e.fields: + return e.fields['year'] - return cmp(toStr(e1), toStr(e2)) + month = e.fields['month'].lower()[0:3] + if month in month2num: + month = month2num[month] + else: + month = "" + + return e.fields['year'] + "-" + month def usage(): @@ -200,8 +202,8 @@ if __name__ == "__main__": print("

" + year + "

") - iteritems = list(entries.iteritems()) - iteritems.sort(cmp=entryCompareDate, reverse=True) + iteritems = list(entries.items()) + iteritems.sort(key=entryDateSortKey, reverse=True) for key, entry in iteritems: if entry.fields['year'] != year: @@ -210,7 +212,8 @@ if __name__ == "__main__": print("
") print("[" + key + "]
") - print(format_entry(entry).encode('utf8')) + e = format_entry(entry) + print(e) print("
\n")