Skip to content

Commit

Permalink
handle broken partial date
Browse files Browse the repository at this point in the history
  • Loading branch information
bdcaf committed Sep 24, 2020
1 parent 2da628b commit a11c423
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions plugin/doi_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def get_title(result):
def _author2string(author):
if author.has_key('family') and author.has_key('given'):
return (u"%s, %s" % (author['family'],author['given']))
elif author.has_key('family') and not author.has_key('given'):
return author['family']
elif author.has_key('name'):
return author['name']
else:
Expand All @@ -80,9 +82,6 @@ def put_language(mi, result):
def put_publisher(mi,result):
if result.has_key('publisher'):
mi.publisher = result['publisher']
def put_pubdate(mi,result):
if result.has_key('issued'):
mi.pubdate = datestr(result['issued'])
def put_tags(mi,result):
if prefs['add_tags'] and result.has_key('subject'):
mi.tags = result['subject']
Expand Down Expand Up @@ -130,7 +129,7 @@ def result2meta(self, result, prev_identifiers={}):

put_publisher(mi,result)
put_language(mi,result)
put_pubdate(mi,result)
self.put_pubdate(mi,result)
put_tags(mi,result)
put_journal(mi, result)
put_series_index(mi, result)
Expand Down Expand Up @@ -164,7 +163,7 @@ def quick_add(key, name=None, joiner=", "):
strval = joiner.join(v)
elif isinstance(v, dict):
if v.has_key('date-parts'):
strval = read_partial_date(v)
strval = self.read_partial_date(v)
else:
strval=v
else:
Expand All @@ -187,8 +186,26 @@ def quick_add(key, name=None, joiner=", "):
# jd ="-".join(map(str,ji['published-print']['date-parts'][0]))
# extra_meta.append("published: %s" % (jd))

def read_partial_date(dp):
return "-".join(map(str,dp['date-parts'][0]))
def datestr(dp):
return parse_date(read_partial_date(dp))
def read_partial_date(self,dp):
if dp.has_key('date-parts'):
return "-".join(map(str,dp['date-parts'][0]))
else:
return None

def datestr(self,dp):
ds = self.read_partial_date(dp)
if ds:
try:
return parse_date(ds)
except Exception as e:
self.log.warning("failed date input", dp)
self.log.warning("failed date result", e)
return None
else:
self.log.warning("unknown date format:", dp)
return None

def put_pubdate(self,mi,result):
if result.has_key('issued'):
mi.pubdate = self.datestr(result['issued'])

0 comments on commit a11c423

Please sign in to comment.