Fix bad error code handling

master
LEdoian 8 months ago
parent 3b4f07663b
commit ddc560a4ae

@ -7,6 +7,7 @@ from datetime import datetime
from dataclasses import dataclass from dataclasses import dataclass
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
import sys
api_url = r'https://review.video.fosdem.org/api/v1/event/1/overview' api_url = r'https://review.video.fosdem.org/api/v1/event/1/overview'
poll_rate = 10*60 # seconds poll_rate = 10*60 # seconds
@ -21,7 +22,7 @@ class TimeSeries:
def get_data() -> tuple[datetime, dict[str, int], dict[str, int]]: def get_data() -> tuple[datetime, dict[str, int], dict[str, int]]:
resp = requests.get(api_url) resp = requests.get(api_url)
# TODO: error handling? if resp.status_code != 200: raise RuntimeError(f'bad status code: {resp.status_code}')
time = datetime.now().astimezone() time = datetime.now().astimezone()
data = json.loads(resp.content.decode()) data = json.loads(resp.content.decode())
states = defaultdict(lambda: 0) states = defaultdict(lambda: 0)
@ -46,12 +47,16 @@ def main():
plt.show(block=False) plt.show(block=False)
while True: while True:
time, states, jobstates = get_data() try:
print(f'data got at {time}') time, states, jobstates = get_data()
assert time not in ts.data print(f'data got at {time}')
ts.data[time] = (states, jobstates) assert time not in ts.data
ts.states |= states.keys() ts.data[time] = (states, jobstates)
ts.jobstates |= jobstates.keys() ts.states |= states.keys()
ts.jobstates |= jobstates.keys()
except RuntimeError as e:
print('Could not get/save data.')
sys.print_exc()
# Save the pickle # Save the pickle
# Should probably save elsewhere and do atomic rename, but whatever. # Should probably save elsewhere and do atomic rename, but whatever.

Loading…
Cancel
Save