Skip to content

Commit 4238caa

Browse files
committed
Update collect_weather_data.py
1 parent f814689 commit 4238caa

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/collect_weather_data.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from concurrent.futures import ThreadPoolExecutor
33
from datetime import datetime, timedelta
44
from tqdm import tqdm
5+
import traceback
56
import requests
67
import asyncio
78
import json
@@ -28,10 +29,10 @@ def fetch_city_weather_data(city : str) -> dict | None:
2829
except (requests.exceptions.ConnectTimeout,
2930
requests.exceptions.ReadTimeout,
3031
requests.exceptions.SSLError,
31-
json.JSONDecodeError,
32+
json.JSONDecodeError,
3233
requests.exceptions.ConnectionError,
3334
AssertionError) as e:
34-
logger.error(e)
35+
logger.error(traceback.format_exc())
3536
return None
3637
else:
3738
return report
@@ -46,11 +47,15 @@ def main(args : Namespace) -> None:
4647
sys.exit(1)
4748

4849
logger.info(f"Starting to fetch weather data for cities: {', '.join(cities)}")
50+
51+
errors = 0
4952
with db as conn:
5053
for city in cities:
5154
report = fetch_city_weather_data(city)
5255

53-
if not report: continue
56+
if not report:
57+
errors += 1
58+
continue
5459

5560
latitude : float = report["nearest_area"][0]["latitude"]
5661
longitude : float = report["nearest_area"][0]["longitude"]
@@ -63,6 +68,8 @@ def main(args : Namespace) -> None:
6368
conn.newReport(report)
6469
logger.info(f"Report for {city:<15} at {dt} created successfully.")
6570

71+
sys.exit(errors)
72+
6673
if __name__ == '__main__':
6774
parser = ArgumentParser(
6875
description="Collect weather data for specified cities",

0 commit comments

Comments
 (0)