File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 2
2
from concurrent .futures import ThreadPoolExecutor
3
3
from datetime import datetime , timedelta
4
4
from tqdm import tqdm
5
+ import traceback
5
6
import requests
6
7
import asyncio
7
8
import json
@@ -28,10 +29,10 @@ def fetch_city_weather_data(city : str) -> dict | None:
28
29
except (requests .exceptions .ConnectTimeout ,
29
30
requests .exceptions .ReadTimeout ,
30
31
requests .exceptions .SSLError ,
31
- json .JSONDecodeError ,
32
+ json .JSONDecodeError ,
32
33
requests .exceptions .ConnectionError ,
33
34
AssertionError ) as e :
34
- logger .error (e )
35
+ logger .error (traceback . format_exc () )
35
36
return None
36
37
else :
37
38
return report
@@ -46,11 +47,15 @@ def main(args : Namespace) -> None:
46
47
sys .exit (1 )
47
48
48
49
logger .info (f"Starting to fetch weather data for cities: { ', ' .join (cities )} " )
50
+
51
+ errors = 0
49
52
with db as conn :
50
53
for city in cities :
51
54
report = fetch_city_weather_data (city )
52
55
53
- if not report : continue
56
+ if not report :
57
+ errors += 1
58
+ continue
54
59
55
60
latitude : float = report ["nearest_area" ][0 ]["latitude" ]
56
61
longitude : float = report ["nearest_area" ][0 ]["longitude" ]
@@ -63,6 +68,8 @@ def main(args : Namespace) -> None:
63
68
conn .newReport (report )
64
69
logger .info (f"Report for { city :<15} at { dt } created successfully." )
65
70
71
+ sys .exit (errors )
72
+
66
73
if __name__ == '__main__' :
67
74
parser = ArgumentParser (
68
75
description = "Collect weather data for specified cities" ,
You can’t perform that action at this time.
0 commit comments