SWeatherpy/main-test.py
2024-10-21 14:39:42 -05:00

44 lines
1.7 KiB
Python

from weathersettings import logger, current_time
from locweatherdata import get_coordinates_from_location, get_gridpoint_forecast, get_forecast, save_data
from forecastformat import format_forecast, display_formatted_forecast
from radar import show_radar_image, find_nearest_nexrad_station, save_radar_image
current_time = current_time
# Main logic
def main():
location = input("Enter location name: ")
logger.info(f"Getting weather data for {location} at {current_time}")
save = input("Save data to JSON file? (y/n) ")
coords = get_coordinates_from_location(location)
if coords:
lat, lon = coords
gridpoint_url = get_gridpoint_forecast(lat, lon)
if gridpoint_url:
forecast_data = get_forecast(gridpoint_url)
if forecast_data:
formatted_data = format_forecast(forecast_data)
display_formatted_forecast(formatted_data)
logger.info(f"Formatted forecast data retrieved and displayed for {location}")
nearest_station = find_nearest_nexrad_station(lat, lon)
if nearest_station:
show_radar_image(nearest_station)
else:
logger.error("Failed to retrieve forecast data")
else:
logger.error("Failed to retrieve gridpoint forecast URL")
else:
logger.error(f"Failed to retrieve coordinates for {location}")
if save.lower() in ['y', 'Y', 'yes', 'Yes']:
save_data(formatted_data)
save_radar_image(nearest_station)
logger.info(f"Formatted forecast data saved to JSON file for {location} at {current_time}")
if __name__ == "__main__":
main()