Skip to content

Commit

Permalink
Gracefully handle zero contributions (e.g. due to lack of permissions)
Browse files Browse the repository at this point in the history
  • Loading branch information
olifre committed Sep 11, 2023
1 parent 1fe9dd4 commit 7ab3f77
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions indico-fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import os
import sys
import time
import urllib.request
import requests
Expand Down Expand Up @@ -53,7 +54,11 @@ def exec_request(indico_instance, request_path):
jresp = json.loads(req.content)
except:
print("Error parsing JSON response!")
os.exit(1)
sys.exit(1)

if not jresp['results']:
print("Error: Zero contributions found! This might be caused by lack of permissions.")
sys.exit(1)

for contrib in jresp['results'][0]['contributions']:
if 'startDate' not in contrib:
Expand All @@ -72,7 +77,7 @@ def exec_request(indico_instance, request_path):
room = contrib['room'].split().pop(-1)
except:
room = contrib['room']

if len(room) > 0:
fulldir += "/" + room
try:
Expand Down Expand Up @@ -111,4 +116,3 @@ def exec_request(indico_instance, request_path):
except Exception as exc:
print(exc)
print(' Encountered unknown error. Continuing.')

0 comments on commit 7ab3f77

Please sign in to comment.