generated from mwc/lab_weather
parent
b2873aaa51
commit
e5c2914a4a
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue