From 6056dcc93fa8111a04d76a7af5bcddb12704cb96 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Sat, 17 Jul 2021 01:29:16 +0200 Subject: pubmed: do not fail when accessing missing file after a sync gap (e.g. 06/07 2021) harvester wanted to fetch a file, that was not on the server (any more) - do not fail in this case we'll need to backfill missing records via full data dump --- python/fatcat_tools/harvest/pubmed.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'python/fatcat_tools/harvest') diff --git a/python/fatcat_tools/harvest/pubmed.py b/python/fatcat_tools/harvest/pubmed.py index f97702c0..98bb7f00 100644 --- a/python/fatcat_tools/harvest/pubmed.py +++ b/python/fatcat_tools/harvest/pubmed.py @@ -20,6 +20,7 @@ import sys import tempfile import time import xml.etree.ElementTree as ET +import zlib from urllib.parse import urlparse import dateparser @@ -114,8 +115,13 @@ class PubmedFTPWorker: url = "ftp://{}{}".format(self.host, path) filename = ftpretr(url) with tempfile.NamedTemporaryFile(prefix='fatcat-ftp-tmp-', delete=False) as decomp: - gzf = gzip.open(filename) - shutil.copyfileobj(gzf, decomp) + try: + gzf = gzip.open(filename) + shutil.copyfileobj(gzf, decomp) + except zlib.error as exc: + print('[skip] retrieving {} failed with {} (maybe empty, missing or broken gzip)'.format( + url, exc), file=sys.stderr) + continue # Here, blob is the unparsed XML; we peek into it to use PMID as # message key. We need streaming, since some updates would consume -- cgit v1.2.3 From 0202f5f9d0c508e2c4cc4af6a8b22bd624bcbd0b Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Sat, 17 Jul 2021 01:38:29 +0200 Subject: pubmed: update docs --- python/fatcat_tools/harvest/pubmed.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'python/fatcat_tools/harvest') diff --git a/python/fatcat_tools/harvest/pubmed.py b/python/fatcat_tools/harvest/pubmed.py index 98bb7f00..fd4af1f4 100644 --- a/python/fatcat_tools/harvest/pubmed.py +++ b/python/fatcat_tools/harvest/pubmed.py @@ -95,8 +95,9 @@ class PubmedFTPWorker: def fetch_date(self, date): """ - Fetch file for a given date and feed Kafka one article per message. If - the fetched XML does not contain a PMID, this method will fail. + Fetch file or files for a given date and feed Kafka one article per + message. If the fetched XML does not contain a PMID an exception is + raised. If no date file mapping is found, this will fail. """ -- cgit v1.2.3