Commit a70841cb authored by Benoit Favre's avatar Benoit Favre
Browse files

fix problems with pubmed servers disconnecting

parent 8f9d71d4
......@@ -5,6 +5,8 @@ import sys, json, re, collections
from pymed import PubMed
from datetime import datetime, date
import requests
import time
pubmed = PubMed(tool="https://covid19.lis-lab.fr", email="benoit.favre@univ-amu.fr")
......@@ -32,16 +34,22 @@ for article in articles['results']:
found = False
for query in ['(%s[Title] AND (%s[Author])' % (preprocess(title), preprocess(authors)), '%s[Title]' % preprocess(title), preprocess(title)]:
results = pubmed.query(query, max_results=30)
for result in results:
entry = result.toDict()
if normalize(title) == normalize(entry['title']):
found = True
for field in ['pubmed_id', 'doi', 'abstract']:
if field in entry:
article[field] = entry[field]
stats[field] += 1
for retries in range(10):
try:
results = pubmed.query(query, max_results=30)
for result in results:
entry = result.toDict()
if normalize(title) == normalize(entry['title']):
found = True
for field in ['pubmed_id', 'doi', 'abstract']:
if field in entry:
article[field] = entry[field]
stats[field] += 1
break
break
except requests.exceptions.HTTPError as e:
print(e, file=sys.stderr)
time.sleep(5)
if found:
break
if not found:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment