Conditions | 3 |
Total Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | """ |
||
22 | @staticmethod |
||
23 | def get_from_wateroffice(remote_id): |
||
24 | province = remote_id.split('_')[0] |
||
25 | url = 'http://dd.weather.gc.ca/hydrometric/csv/{}/hourly/{}_hourly_hydrometric.csv'.format(province, remote_id) |
||
26 | response = requests.get(url) |
||
27 | riter = response.iter_lines(decode_unicode=True) |
||
28 | next(riter) |
||
29 | reader = csv.reader(riter) |
||
30 | lines = [] |
||
31 | for row in reader: |
||
32 | lines.append(row) |
||
33 | last = lines[-1] |
||
34 | level = float(last[2]) |
||
35 | try: |
||
36 | discharge = float(last[6]) |
||
37 | except ValueError: |
||
38 | discharge = None |
||
39 | dt = arrow.get(last[1]).datetime |
||
40 | |||
41 | return dt, level, discharge |
||
42 | |||
50 |