Skip to content

Commit ddb6112

Browse files
committed
Exception handling
1 parent 0ba150d commit ddb6112

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

update_periods.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@ def period_start(period):
1212

1313
if response.status_code == 200:
1414
data = json.loads(response.content)
15-
startUri = data["result"]["primaryTopic"]["hasBeginning"]["_about"] + "Time"
16-
17-
response = requests.get(api_root + startUri)
18-
19-
if response.status_code == 200:
20-
data = json.loads(response.content)
21-
return(data["result"]["primaryTopic"]["numericPosition"])
22-
else:
23-
print("Could not load beginning from: " + startUri)
15+
try:
16+
startUri = data["result"]["primaryTopic"]["hasBeginning"]["_about"] + "Time"
17+
18+
response = requests.get(api_root + startUri)
19+
20+
if response.status_code == 200:
21+
data = json.loads(response.content)
22+
try:
23+
return(data["result"]["primaryTopic"]["numericPosition"])
24+
except:
25+
print("Could not load numericPosition from : " + startUri)
26+
return 0
27+
else:
28+
print("Could not load beginning from: " + startUri)
29+
return 0
30+
except:
31+
print("Could not load beginning for: " + period)
2432
return 0
2533

34+
2635
else:
2736
print("Could not load info from: " + period)
2837
return 0

0 commit comments

Comments
 (0)