Commit 2bcee882 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update controller and views wizards/update_citations to add protection.

parent cd69868e
......@@ -453,6 +453,8 @@ def update_citations():
http_error=0,
insert=0,
json_error=0,
list_size=0,
not_list=0,
url_error=0)
# get user requirement
......@@ -474,7 +476,19 @@ def update_citations():
try:
url = rex_ins.search(row.origin).group(1)
rep = store.interogate(url, timeout=60, **kwargs)
count = rep.json()[0].get("number_of_citations")
lst = rep.json()
if not isinstance(lst, list):
logger.warning(f"JSON response is not a list")
counters.not_list += 1
continue
if len(lst) != 1:
logger.warning(f"size of the return list is not one")
counters.list_size += 1
continue
count = lst[0].get("number_of_citations")
except AttributeError:
logger.warning(f"inspirehep URL not well formed {row.origin}")
......@@ -518,6 +532,8 @@ def update_citations():
logger.info(f" bad inspirehep URL: {counters.url_error}")
logger.info(f" HTTP connection error: {counters.url_error}")
logger.info(f" JSON decoding error: {counters.json_error}")
logger.info(f" response is not a list: {counters.not_list}")
logger.info(f" list size is not one: {counters.list_size}")
logger.info(f" insert or update in db: {counters.insert}")
return dict(counters=counters,
......
......@@ -377,6 +377,7 @@
'List of university separated by comma': 'Liste des universités séparé par une virgule',
'List shorted by AERES category, by project and by year': 'Liste triée par catégorie AERES par projet et par année',
'List shorted by usual category, by team and by year': 'Liste triée par catégorie usuelle par équipe et par année',
'list size is not one': "La liste a plus d'un élément",
'lists': 'listes',
'Load': 'Charger',
'load in the database': 'chargé dans la base de données',
......@@ -623,6 +624,7 @@
'Reports or notes signed by members of the institute': 'Rapports ou notes signés par des membres du laboratoire',
'Request reset password': 'Request reset password',
'Reset Password key': 'Reset Password key',
'response is not a list': "La réponse n'est pas une liste",
'Review': 'Revue',
'Revue': 'Revue',
'Revues': 'Revues',
......
......@@ -9,6 +9,8 @@
[T("URL not well formed"), TD(f"{counters.url_error}", _style=mytd)],
[T("HTTP connection error"), TD(f"{counters.http_error}", _style=mytd)],
[T("JSON decoding error"), TD(f"{counters.json_error}", _style=mytd)],
[T("response is not a list"), TD(f"{counters.not_list}", _style=mytd)],
[T("list size is not one"), TD(f"{counters.list_size}", _style=mytd)],
[T("Number of articles modified"), TD(f"{counters.insert}", _style=mytd)]]
title = f"{T('Update citations')} {team_project}"
......
......@@ -7,16 +7,18 @@
start = request.now
end = datetime.now()
delta = (end - start).total_seconds()
delta = end - start
response.write(f"\t Scan start: {start:%d %b %Y %H:%M}\n")
response.write(f"\t Scan end: {end:%d %b %Y %H:%M}\n")
response.write(f"\t Scan duration: {delta:.0f}s\n\n")
response.write(f"\t Scan duration: {delta}\n\n")
response.write(f"\tNumber of articles analysed: {counters.article}\n")
response.write(f"\t URL not well formed: {counters.url_error}\n")
response.write(f"\t HTTP connection error: {counters.http_error}\n")
response.write(f"\t JSON decoding error: {counters.json_error}\n")
response.write(f"\t response is not a list: {counters.not_list}\n")
response.write(f"\t list size is not one: {counters.list_size}\n")
response.write(f"\tNumber of articles modified: {counters.insert}\n\n")
}}
\ No newline at end of file
Markdown is supported
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