#-*- coding: utf-8 -*- # (c) 2012-2013 Anders Andersen # See http://www.cs.uit.no/~aa/dist/tools/py/COPYING for details # Import my module for parsing the cristin json format # (http://www.cs.uit.no/~aa/dist/tools/py/cristin.py) from cristin import * # Read from stdin mypubl = json.load(sys.stdin) # I keep my abstracts (OMTALE) here MYURL = "http://www.cs.uit.no/~aa/pub/" # Do produce the output mset = []; publist = {} for publ in mypubl["forskningsresultat"]: # publ is a dict with "fellesdata" and "kategoridata" (possibly empty) info = {} selected = False # "fellesdata" includes authors, category and title info.update(getit(publ["fellesdata"], commonmap)) # "kategoridata" includes information about where/how kd = publ["kategoridata"] if type (kd) is dict and len(kd) == 1: cat = list(kd.keys())[0] info.update(getit(publ["kategoridata"][cat], catmap[cat])) else: warning("No where/how: %s" % (info["title"],)) cat = "" # Fetch authors and title author = "" other = "" for a in info["authors"]: if type(a["more"]) is list: rolle = a["more"][0]["sted"]["rolle"] else: rolle = a["more"]["sted"]["rolle"] if rolle["kode"] != "FORFATTER": other += a["fname"] + " " + a["lname"] + " (" + rolle["navnEngelsk"] + "), " else: author += a["fname"] + " " + a["lname"] + ", " author = (author + other)[:-2] title = info["title"] # Fetch ref (if any) ref = {} if "ref" in info: for r in info["ref"]: if "kode" in r and "url" in r: if r["kode"]["kode"] == "OMTALE" and MYURL in r["url"]: ref["Details"] = r["url"] selected = True else: ref[r["kode"]["navnEngelsk"]] = r["url"] # Only selected papers (OMTALE conatins MYURL)? if "-s" in sys.argv and not selected: continue # Get the rest of the info where = "" for k in order: if k in info: if k == "issn": where += ", ISSN " + info[k] elif k == "isbn": where += ", ISBN " + info[k] elif k == "vol": where += ", Vol. " + info[k] elif k == "no": where += ", No. " + info[k] elif k == "from": where += ", pp. " + info[k] elif k == "to": where += "-" + info[k] else: where += ", " + info[k] # mcat or scat? if "mcat" in info: mscat = "%s: %s -> %s" % (repr(cat), repr(info["mcat"]), repr(info["scat"])) if (cat, info["mcat"], info["scat"]) in tmap: info["category"] = tmap[(cat, info["mcat"], info["scat"])] else: warning("Unknown category: (%s, %s, %s)" % (cat, info["mcat"], info["scat"])) if not mscat in mset: mset.append(mscat) else: warning("No category set: " + info["title"]) # Add references (urls) where2 = "" if "-a" in sys.argv and len(ref) > 0: where2 = " [" for k in ref: where2 += '%s, ' % (ref[k], k) where2 = where2[:-2] + "]" # Produce and print entry (entry2: with links) entry = ("
%s, %s%s.
" % (author, title, where)).encode( "ascii", "xmlcharrefreplace") entry2 = ("%s, %s%s%s.
" % (author, title, where, where2)).encode( "ascii", "xmlcharrefreplace") try: if "Details" in ref: if info["category"] == "Conference presentations" or info["category"] == "Posters": if not "-s" in sys.argv: addit(publist, info["category"], entry) addit(publist, "Conference publications", entry2) elif (info["category"] == "Master student thesises" or info["category"] == "PhD student thesises"): addit(publist, "Thesises", entry2) elif (info["category"] == "Conference publications" and "issn" in info): addit(publist, "Journal publications", entry2) else: addit(publist, info["category"], entry2) else: addit(publist, info["category"], entry2) except KeyError: warning("error in info dict: " + str(info)) for c in porder: if c in publist: print("