Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FiveDaysWeatherForecast:
- days = None
- def __init__(self,location):
- self.location = location
- def _parsing_url(self,accu_api):
- url1 = f"http://dataservice.accuweather.com/forecasts/v1/daily/5day/"
- url2 = f"{self.location}?apikey={accu_api}&details=true"
- absolute_url = urljoin(url1, url2)
- return absolute_url
- def get_forecast(self):
- url = self._parsing_url(accu_api)
- api_response = requests.get(url)
- weather_forcast = api_response.json()
- return weather_forcast
- def weather_details(self, weather_forcast, days=5):
- forecast = self.get_forecast()
- for i in range(days):
- min_temp = forecast['DailyForecasts'][i]['Temperature']['Minimum']['Value']
- max_temp = forecast['DailyForecasts'][i]['Temperature']['Maximum']['Value']
- phrase = forecast['DailyForecasts'][i]['Day']['LongPhrase']
- probability = forecast['DailyForecasts'][i]['Day']['RainProbability']
- wind_speed = forecast['DailyForecasts'][i]['Day']['Wind']['Speed']['Value']
- yield (min_temp, max_temp, phrase, probability, wind_speed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement