-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
33 lines (24 loc) · 936 Bytes
/
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
from pathlib import Path
from coordinates import get_coords
from weather_api_service import get_weather
from weather_formatter import format_weather
from exeptions import CantGetCoordinates, ApiServiceError
from history import save_weather, PlainFileWeatherStorage, JSONFileWeatherStorage
def main():
try:
coordinates = get_coords()
except CantGetCoordinates:
print('Ошибка: Не удалось получить координаты')
exit(1)
try:
weather = get_weather(coordinates)
except ApiServiceError:
print('Ошибка: Не удалось получить погоду')
exit(1)
# save_weather(weather,
# PlainFileWeatherStorage(Path.cwd() / 'history.txt'))
save_weather(weather,
JSONFileWeatherStorage(Path.cwd() / 'history.json'))
print(format_weather(weather))
if __name__ == '__main__':
main()