-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (37 loc) · 1.9 KB
/
main.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
from vancouver_earthquake.core.earthquake import Earthquake
import vancouver_earthquake.core.network_manager as network_manager
from vancouver_earthquake.social.social_manager import social_manager
import vancouver_earthquake.storage.storage_manager as storage_manager
TOP_BOUNDING_BOX = 53.7827
BOTTOM_BOUNDING_BOX = 44.7827
LEFT_BOUNDING_BOX = -132.2207
RIGHT_BOUNDING_BOX = -114.0207
OLD_PATH = "outputs/old_earthquake.json"
def in_boundary(
earthquakes: list[Earthquake],
top: float = TOP_BOUNDING_BOX,
bottom: float = BOTTOM_BOUNDING_BOX,
left: float = LEFT_BOUNDING_BOX,
right: float = RIGHT_BOUNDING_BOX
) -> list[Earthquake]:
""" This function will return the list of earthquake, if the earthquake is in the boundary of Vancouver. """
return [eq for eq in earthquakes if right > eq.longitude > left and top > eq.latitude > bottom]
def filter_out_duplicate_earthquake(old_eq: list[Earthquake], new_eq: list[Earthquake]) -> list[Earthquake]:
""" This function will return earthquakes from new_eq not present in old_eq. """
return [eq for eq in new_eq if eq not in old_eq]
def main():
new_earthquakes: list[Earthquake] = network_manager.get_earthquake_data()
new_earthquakes = in_boundary(earthquakes=new_earthquakes)
if not new_earthquakes:
print("No earthquake in Vancouver.")
return
old_earthquakes: list[Earthquake] = storage_manager.read_earthquake_data(old_eq_path=OLD_PATH)
storage_manager.write_earthquake_data(new_eq=new_earthquakes, old_path=OLD_PATH)
filtered_earthquakes: list[Earthquake] = filter_out_duplicate_earthquake(old_eq=old_earthquakes,
new_eq=new_earthquakes)
if not filtered_earthquakes:
print("No valid earthquake after filtered.")
return
social_manager(earthquakes=filtered_earthquakes)
if __name__ == '__main__':
main()