Skip to content
Snippets Groups Projects
Commit a70841cb authored by Benoit Favre's avatar Benoit Favre
Browse files

fix problems with pubmed servers disconnecting

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