Files
lab_weather/weather/weather.py

49 lines
1.7 KiB
Python

# 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):
"""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.
"""
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 find 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'}")
if verbose:
print(f"Wind Direction: {period['wind_direction']}")
print(f"Wind Speed: {period['wind _speed']}\n")
# print("Not finished...") # YOUR CODE HERE!
# print(location)