Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. class FiveDaysWeatherForecast:
  2.     days = None
  3.  
  4.     def __init__(self,location):
  5.         self.location = location
  6.  
  7.     def _parsing_url(self,accu_api):
  8.         url1 = f"http://dataservice.accuweather.com/forecasts/v1/daily/5day/"
  9.         url2 = f"{self.location}?apikey={accu_api}&details=true"
  10.         absolute_url = urljoin(url1, url2)
  11.         return absolute_url
  12.  
  13.     def get_forecast(self):
  14.         url = self._parsing_url(accu_api)
  15.  
  16.         api_response = requests.get(url)
  17.         weather_forcast = api_response.json()
  18.         return weather_forcast
  19.  
  20.     def weather_details(self, weather_forcast, days=5):
  21.         forecast = self.get_forecast()
  22.         for i in range(days):
  23.             min_temp = forecast['DailyForecasts'][i]['Temperature']['Minimum']['Value']
  24.             max_temp = forecast['DailyForecasts'][i]['Temperature']['Maximum']['Value']
  25.             phrase = forecast['DailyForecasts'][i]['Day']['LongPhrase']
  26.             probability = forecast['DailyForecasts'][i]['Day']['RainProbability']
  27.             wind_speed = forecast['DailyForecasts'][i]['Day']['Wind']['Speed']['Value']
  28.             yield (min_temp, max_temp, phrase, probability, wind_speed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement