#!/usr/bin/env python2.7 import sys, demjson def debracify(x): if type(x) == list: return [debracify(i) for i in x] elif type(x) == str or type(x) == unicode: return str(x.replace("{", "").replace("}", "")) elif type(x) == dict: newdict = {} for k, v in x.iteritems(): newdict[k] = debracify(v) return newdict else: return x n = 0 def tweakAuthors(x): if type(x) == list: return [tweakAuthors(i) for i in x] elif type(x) == dict: newdict = {} for k, v in x.iteritems(): newdict[k] = tweakAuthors(v) if "type" in newdict and newdict["type"] == "Author": # fix up name and ID newdict["last-name-first"] = newdict["label"] newdict["id"] = newdict["label"] newdict["label"] = newdict["original-name"] # Set the id to be the bibtex key if "key" in newdict: newdict["id"] = newdict["key"] if "type" in newdict and newdict["type"] == "Publication": # Tag WIPs and posters as separate categories if "note" in newdict: if "Work in Progress" in newdict["note"]: newdict["pub-type"] = "wipposter" elif "Poster" in newdict["note"]: newdict["pub-type"] = "wipposter" # Make theses have a single category if "pub-type" in newdict: pubtype = [] if type(newdict["pub-type"]) is list: pubtype = newdict["pub-type"] else: pubtype = [newdict["pub-type"]] if any("thesis" in t for t in pubtype): # ...but put the type of the thesis in a note if "note" in newdict: newdict["note"] += ". " else: newdict["note"] = "" if any("master" in t for t in pubtype): newdict["note"] += "Master's thesis" elif any("phd" in t for t in pubtype): newdict["note"] += "Ph.D. thesis" newdict["pub-type"] = "thesis" # uniquify the date for sorting purposes. Yuck. if "date" in newdict: global n n = n + 1 newdict["date"] = newdict["date"]+"-"+str(n) # XXX hack for Hank: put tech reports at bottom if newdict["pub-type"] not in ["inproceedings", "journal"]: newdict["date"] = "0-"+newdict["date"] newdict["pub-type-not-superseded"] = newdict["pub-type"] if "supersededby" in newdict: newdict["pub-type"] = "superseded" return newdict else: return x # Decode with pyparsin/jsonParser and encode with simplejson because # simplejson seems to be overly strict. #json = jsonParser.jsonObject.parseString(sys.stdin.read()) json = sys.stdin.read() tree = demjson.decode(json) newjson = demjson.encode(tweakAuthors(debracify(tree))) print newjson