generated from CambridgeEngineering/PartIA-Flood-Warning-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task2D.py
51 lines (39 loc) · 1.37 KB
/
Task2D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Copyright (C) 2018 Garth N. Wells
#
# SPDX-License-Identifier: MIT
import datetime
from floodsystem.datafetcher import fetch_measure_levels
from floodsystem.stationdata import build_station_list
def run():
# Build list of stations
stations = build_station_list()
# Station name to find
station_name = "Cam"
# Find station
station_cam = None
for station in stations:
if station.name == station_name:
station_cam = station
break
# Check that station could be found. Return if not found.
if not station_cam:
print("Station {} could not be found".format(station_name))
return
# Alternative find station 'Cam' using the Python 'next' function
# (https://docs.python.org/3/library/functions.html#next). Raises
# an exception if station is not found.
# try:
# station_cam = next(s for s in stations if s.name == station_name)
# except StopIteration:
# print("Station {} could not be found".format(station_name))
# return
# Fetch data over past 2 days
dt = 2
dates, levels = fetch_measure_levels(
station_cam.measure_id, dt=datetime.timedelta(days=dt))
# Print level history
for date, level in zip(dates, levels):
print(date, level)
if __name__ == "__main__":
print("*** Task 2D: CUED Part IA Flood Warning System ***")
run()