66from bibtexparser .bibdatabase import BibDatabase
77import dateutil .parser as parser
88import pytz
9+ import re
910
1011export_ns = Namespace ("export" , description = "metadata export API operations" )
1112
@@ -20,15 +21,27 @@ def parse_date(date):
2021 parsed_date ["day" ] = str (dt .day )
2122 return parsed_date
2223
24+ def create_authorfield (authors_objects ):
25+ authors = []
26+ for ao in authors_objects :
27+ if "lastName" in ao :
28+ author = ao ["lastName" ]
29+ if "lastName" in ao and "firstName" in ao :
30+ author = "{lastName}, {firstName}" .format (** ao )
31+ authors .append (author )
32+ authorstring = " and " .join (authors )
33+ return authorstring
34+
2335def transform2bibtex (metadata ):
2436 # TODO: add mapping from resulttype to ARTICLETYPE
2537 # possible published_in parser
2638 # field renaming, e.g. paper_abstract to abstract
2739 # choose correct fields, e.g. author_string for author
2840 # use different field for ID
2941 title = metadata .get ("title" , "" )
30- author = metadata .get ("authors " , "" )
42+ author = create_authorfield ( metadata .get ("authors_objects " , []) )
3143 doi = metadata .get ("doi" , "" )
44+ doi = re .sub ("https://|http://|dx.doi.org/|doi.org/" , "" , doi )
3245 id = metadata .get ("id" , "" )
3346 published_in = metadata .get ("published_in" , "" )
3447 url = metadata .get ("list_link" , {}).get ("address" , "" )
0 commit comments