diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/fatcat_tools/importers/crossref.py | 17 | ||||
-rw-r--r-- | python/fatcat_tools/importers/grobid_metadata.py | 6 | ||||
-rw-r--r-- | python/fatcat_tools/transforms.py | 4 | ||||
-rw-r--r-- | python/fatcat_web/templates/creator_view.html | 5 | ||||
-rw-r--r-- | python/fatcat_web/templates/release_search.html | 4 | ||||
-rw-r--r-- | python/fatcat_web/templates/release_view.html | 6 | ||||
-rw-r--r-- | python/fatcat_web/templates/work_view.html | 4 |
7 files changed, 31 insertions, 15 deletions
diff --git a/python/fatcat_tools/importers/crossref.py b/python/fatcat_tools/importers/crossref.py index 1ea47707..13179207 100644 --- a/python/fatcat_tools/importers/crossref.py +++ b/python/fatcat_tools/importers/crossref.py @@ -250,16 +250,18 @@ class CrossrefImporter(FatcatImporter): return None # release date parsing is amazingly complex - release_date = obj['issued']['date-parts'][0] - if not release_date or not release_date[0]: + raw_date = obj['issued']['date-parts'][0] + if not raw_date or not raw_date[0]: # got some NoneType, even though at least year is supposed to be set + release_year = None release_date = None - elif len(release_date) == 3: - release_date = datetime.date(year=release_date[0], month=release_date[1], day=release_date[2]) + elif len(raw_date) == 3: + release_year = raw_date[0] + release_date = datetime.date(year=raw_date[0], month=raw_date[1], day=raw_date[2]) else: - # only the year is actually required; mangle to first day for date - # (TODO: something better?) - release_date = datetime.date(year=release_date[0], month=1, day=1) + # sometimes only the year is included, not the full date + release_year = raw_date[0] + release_date = None re = fatcat_client.ReleaseEntity( work_id=None, @@ -277,6 +279,7 @@ class CrossrefImporter(FatcatImporter): pmcid=extids['pmcid'], wikidata_qid=extids['wikidata_qid'], release_date=release_date, + release_year=release_year, issue=obj.get('issue'), volume=obj.get('volume'), pages=obj.get('page'), diff --git a/python/fatcat_tools/importers/grobid_metadata.py b/python/fatcat_tools/importers/grobid_metadata.py index b84f7145..47a753a6 100644 --- a/python/fatcat_tools/importers/grobid_metadata.py +++ b/python/fatcat_tools/importers/grobid_metadata.py @@ -66,9 +66,10 @@ class GrobidMetadataImporter(FatcatImporter): refs.append(ref) release_date = None + release_year = None if obj.get('date'): - # TODO: only returns year, ever? how to handle? - release_date = datetime.datetime(year=int(obj['date'][:4]), month=1, day=1).date() + # only returns year, ever? + release_year = int(obj['date'][:4]) if obj.get('doi'): extra['doi'] = obj['doi'] @@ -88,6 +89,7 @@ class GrobidMetadataImporter(FatcatImporter): title=obj['title'].strip(), release_type="article-journal", release_date=release_date, + release_year=release_year, contribs=contribs, refs=refs, publisher=obj['journal'].get('publisher'), diff --git a/python/fatcat_tools/transforms.py b/python/fatcat_tools/transforms.py index 516b68ae..843c00a5 100644 --- a/python/fatcat_tools/transforms.py +++ b/python/fatcat_tools/transforms.py @@ -48,6 +48,10 @@ def release_to_elasticsearch(release): if release.release_date: # .isoformat() results in, eg, '2010-10-22' (YYYY-MM-DD) t['release_date'] = release.release_date.isoformat() + if release.release_year is None: + t['release_year'] = release.release_date.year + if release.release_year is not None: + t['release_year'] = release.release_year container = release.container container_is_kept = False diff --git a/python/fatcat_web/templates/creator_view.html b/python/fatcat_web/templates/creator_view.html index 2ce01fb6..802ca4c9 100644 --- a/python/fatcat_web/templates/creator_view.html +++ b/python/fatcat_web/templates/creator_view.html @@ -34,8 +34,9 @@ <p>This creator has contributed to: <ul> {% for release in releases %} - <li>"{{ release.title }}", a {{ release.release_type }} published {{ release.release_date }} - {% if release.release_status != None %}(status: <code>{{ release.release_status }})</code>{% endif %}. + <li>"{{ release.title }}", a {{ release.release_type }} + {% if release.release_year != None %}published in {{ release.release_year }}{% endif %} + {% if release.release_status != None %}(status: <code>{{ release.release_status or "(unknown)" }})</code>{% endif %}. <br>Fatcat ID: <a href="/release/{{ release.ident }}"><code>{{ release.ident }}</code></a> {% endfor %} </ul> diff --git a/python/fatcat_web/templates/release_search.html b/python/fatcat_web/templates/release_search.html index 18bda117..c6a6df60 100644 --- a/python/fatcat_web/templates/release_search.html +++ b/python/fatcat_web/templates/release_search.html @@ -31,8 +31,8 @@ {% if paper.doi %} DOI: <a href="https://doi.org/{{paper.doi }}" style="color: green;">{{ paper.doi }}</a> - {{ paper.release_type }} - {% if paper.release_date %} - - {{ paper.release_date[:4] }} + {% if paper.release_year %} + - {{ paper.release_year }} {% endif %} <br> {% endif %} diff --git a/python/fatcat_web/templates/release_view.html b/python/fatcat_web/templates/release_view.html index 85492eba..fd86b7c9 100644 --- a/python/fatcat_web/templates/release_view.html +++ b/python/fatcat_web/templates/release_view.html @@ -22,7 +22,11 @@ <div class="one wide column"></div> <div class="ten wide column" style="font-size: 16px;"> -{% if release.release_date != None %}<p><b>Date (published):</b> {{ release.release_date }}{% endif %} +{% if release.release_date != None %} + <p><b>Date (published):</b> {{ release.release_date }} +{% elif release.release_year != None %} + <p><b>Date (published):</b> {{ release.release_year }} +{% endif %} {% if release.pmid != None %} <br><b>PubMed:</b> <a href="https://www.ncbi.nlm.nih.gov/pubmed/{{ release.pmid }}"> <code>{{ release.pmid }}</code></a> {% endif %} diff --git a/python/fatcat_web/templates/work_view.html b/python/fatcat_web/templates/work_view.html index 87120e63..c767e1ba 100644 --- a/python/fatcat_web/templates/work_view.html +++ b/python/fatcat_web/templates/work_view.html @@ -34,7 +34,9 @@ still reference the same underlying "work". {% if releases != [] %} <ul> {% for release in releases %} - <li>"{{ release.title }}", a {{ release.release_type }} published {{ release.release_date }} as <code>{{ release.release_status }}</code>. + <li>"{{ release.title }}", a {{ release.release_type }} published + {% if release.release_year != None %}in {{ release.release_year }}{% endif %} + as <code>{{ release.release_status or "(unknown)" }}</code>. <br><a href="/release/{{ release.ident }}"><code>{{ release.ident }}</code></a> {% endfor %} </ul> |