diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..edef7b2 Binary files /dev/null and b/.DS_Store differ diff --git a/weather/weather.py b/weather/weather.py index 75fd2f6..d65aa39 100644 --- a/weather/weather.py +++ b/weather/weather.py @@ -12,13 +12,51 @@ from weather.weather_apis import ( geocode_location, estimate_location, get_weather_office, - get_forecast + get_forecast, ) + def print_weather(location=None, metric=False, verbose=False): """Prints out a weather report using the provided location, or using the user's current location if no location was provided. When metric is True, prints out the weather in metric units. When verbose is True, prints out a more detailed report. """ - print("Not finished...") # YOUR CODE HERE! + try: + if not location: + location = estimate_location() + print(f"Estimated location: {location}") + + if location: + loc_data = geocode_location(location) + if loc_data: + lat, lng = loc_data['lat'], loc_data['lng'] + weather_office = get_weather_office(lat, lng) + if weather_office: + forecast = get_forecast(weather_office, lat, lng) + print(forecast) + + if forecast: + # print_forecast(forecast, metric, verbose) + forecast=get_forecast(forecast, metric, verbose) + print(forecast) + else: + print("No forecast available for the location.") + else: + print("Weather office not found for the given location.") + else: + print("Location not found.") + else: + print("No location provided, and estimated location failed.") + except Exception as e: + print(f"An error occurred: {e}") + + + # if location == None: + # if metric == False: + # return get_weather_office(estimate_location(ip_address=None)) + + # print("Not finished...") # YOUR CODE HERE! +# weather_cli( +# get_forecast( +# get_weather_office(