Files
lab_weather/weather/weather.py
kdang 4eb17103c6 I was able to write code that prints a weather forecast to my liking.
I used some code from older functions to help me write the newer program.

All these systems involve using named arguments to run certain actions.
2025-11-07 09:24:40 -05:00

35 lines
1.2 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:
coordinates = geocode_location(location)
else:
coordinates = estimate_location()
office = get_weather_office(coordinates["lat"], coordinates["lng"])
forecast = get_forecast(office["office"], office["x"], office["y"], metric=metric)
for day in forecast:
display = day["name"] + " Temperature: " + str(day["temperature"]) + " Wind Speed: " + str(day["wind_speed"]) + " Weather: " + day["description"]
print(display)