# weather.py # ------------ # By MWC Contributors # # Defines `print_weather`, which does all the work of fetching # the requested weather data and printing it out to the screen # in a sensible way. # # It's your job to implement this function. from weather.weather_apis import ( geocode_location, estimate_location, get_weather_office, get_forecast ) def print_weather(location=None, metric=False, verbose=False): if location: lct=geocode_location(location) show_lct=location else: lct=estimate_location() show_lct="Estimate location" weatheroffice=get_weather_office(lct['lat'],lct ['lng']) if not weatheroffice: print('Unable to find weather office data') forecast=get_forecast(weatheroffice['office'], weatheroffice['x'], weatheroffice['y'], metric=metric) if not forecast: print('Unable to retrieve forecast data') print(f"Location: {show_lct if location else estimate_location()}\n ______________ \n") for period in forecast: print(f"{period['name']}") print(f"Description: {period['description']}") print(f"Temperature: {period['temperature']}{'C' if metric else 'F'}\n") if verbose: print(f"Wind Direction: {period['wind_direction']}") print(f"Wind Speed: {period['wind_speed']}")