From c589ab81882e2f5ad3f82b612c2b51b843f75b49 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:38:56 +0000 Subject: [PATCH 1/2] A try-except block was added to handle JSON decoding errors so that the for-loop can continue if an error occurs. --- scripts/auto-add-from-zenodo-communities.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/auto-add-from-zenodo-communities.py b/scripts/auto-add-from-zenodo-communities.py index 19f17554..bc105678 100644 --- a/scripts/auto-add-from-zenodo-communities.py +++ b/scripts/auto-add-from-zenodo-communities.py @@ -50,10 +50,13 @@ def main(): response = requests.get('https://zenodo.org/api/records', params={'communities': community, 'access_token': token}) - online_data = response.json() - hits = online_data["hits"]["hits"] - urls = [u["links"]["self_html"] for u in hits] - + try: + online_data = response.json() + hits = online_data["hits"]["hits"] + urls = [u["links"]["self_html"] for u in hits] + except requests.exceptions.JSONDecodeError: + print(f"Error decoding JSON for community: {community}") + continue # compare which new is not in old @@ -100,6 +103,5 @@ def main(): - if __name__ == "__main__": main() From d3b590b87ec3459bd27d1c6457212c04aead89dd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:39:59 +0000 Subject: [PATCH 2/2] urls = [zen --- scripts/generate_link_lists.py | 38 +++++----------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/scripts/generate_link_lists.py b/scripts/generate_link_lists.py index 16db10d9..82cc7761 100644 --- a/scripts/generate_link_lists.py +++ b/scripts/generate_link_lists.py @@ -321,7 +321,11 @@ def read_zenodo(record): # Download the file response = requests.get(url) - data = response.json() + try: + data = response.json() + except json.JSONDecodeError: + data = {} + return data @@ -495,35 +499,3 @@ def complete_zenodo_data(zenodo_url): """ zenodo_data = read_zenodo(zenodo_url) entry = {} - urls = [zenodo_url] - - if 'doi_url' in zenodo_data.keys(): - doi_url = zenodo_data['doi_url'] - - # Add DOI URL to the URLs list if it's not already there - if doi_url not in urls: - urls.append(doi_url) - entry['url'] = urls - - if 'metadata' in zenodo_data.keys(): - metadata = zenodo_data['metadata'] - # Update entry with Zenodo metadata and statistics - entry['name'] = metadata['title'] - if 'publication_date' in metadata.keys(): - entry['publication_date'] = metadata['publication_date'] - if 'description' in metadata.keys(): - entry['description'] = remove_html_tags(metadata['description']) - if 'creators' in metadata.keys(): - creators = metadata['creators'] - entry['authors'] = [c['name'] for c in creators] - if 'license' in metadata.keys(): - entry['license'] = metadata['license']['id'] - - if 'stats' in zenodo_data.keys(): - entry['num_downloads'] = zenodo_data['stats']['downloads'] - - return entry - - -if __name__ == "__main__": - main()