Datasets:
Upload main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from weather_data_fetcher import WeatherDataFetcher
|
| 2 |
+
from datetime import datetime
|
| 3 |
+
|
| 4 |
+
def main():
|
| 5 |
+
api_key = 'e3ade4ad29e02a1ad5127ec56fbc0064'
|
| 6 |
+
fetcher = WeatherDataFetcher(api_key)
|
| 7 |
+
cities = ['Raleigh,NC,US', 'Asheville,NC,US','New Bern,NC,US','Winnabow,NC,US'
|
| 8 |
+
'Chapel Hill,NC,US','Charlotte,NC,US','Greenville,NC,US','Greensboro,NC,US',
|
| 9 |
+
'Wilmington,NC,US','Durham,NC,US']
|
| 10 |
+
|
| 11 |
+
start_date = datetime(2023, 3, 19)
|
| 12 |
+
end_date = datetime(2024, 3, 16)
|
| 13 |
+
|
| 14 |
+
all_cities_df = fetcher.fetch_weather_for_cities(cities, start_date, end_date)
|
| 15 |
+
|
| 16 |
+
if not all_cities_df.empty:
|
| 17 |
+
print(all_cities_df.head())
|
| 18 |
+
else:
|
| 19 |
+
print("No weather data retrieved for any city.")
|
| 20 |
+
file_name = 'weather_data.csv'
|
| 21 |
+
fetcher.save_to_csv(all_cities_df, file_name)
|
| 22 |
+
|
| 23 |
+
if __name__ == '__main__':
|
| 24 |
+
main()
|