generated from mwc/lab_weather
I got stuck on how to effectively use dictionaries to store and retrieve weather data. Me and my partner discussed the problem and broke it down into smaller parts and lookes back on how to fix this with a little bit of assistance.
These systems all involve multiple components working together
This commit is contained in:
@@ -21,4 +21,39 @@ def print_weather(location=None, metric=False, verbose=False):
|
||||
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!
|
||||
# Determine coordinates from the provided location or estimate from IP
|
||||
coords = geocode_location(location) if location else estimate_location()
|
||||
if not coords:
|
||||
print("Error: could not determine location.")
|
||||
return None
|
||||
|
||||
office = get_weather_office(coords["lat"], coords["lng"])
|
||||
if not office:
|
||||
print("Error: no weather office found for location.")
|
||||
return None
|
||||
|
||||
forecast = get_forecast(office["office"], office["x"], office["y"], metric=metric)
|
||||
if not forecast:
|
||||
print("Error: could not fetch forecast data.")
|
||||
return None
|
||||
|
||||
def icon_for(desc: str) -> str:
|
||||
d = (desc or "").lower()
|
||||
if "thunder" in d:
|
||||
return "Today will thunder ⚡"
|
||||
if "rain" in d or "shower" in d:
|
||||
return "Today will have rain showers ☔"
|
||||
if "snow" in d or "sleet" in d:
|
||||
return "Today will snow ❄"
|
||||
if "fog" in d or "haze" in d:
|
||||
return "Today will have fog, limiting your vision 🌫️"
|
||||
if "sun" in d or "clear" in d:
|
||||
return "Today will be Sunny, enjoy the outdoors! ☀️"
|
||||
if "cloud" in d or "overcast" in d:
|
||||
return "Today will be Cloudy ☁️"
|
||||
return ""
|
||||
|
||||
for day in forecast:
|
||||
symbol = icon_for(day["description"])
|
||||
print(symbol)
|
||||
display = day["name"]
|
||||
|
||||
Reference in New Issue
Block a user