Advertisement
Jim_Moonrock

Weather

Jun 29th, 2022
742
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None
  1. import requests
  2. from dataclasses import dataclass
  3.  
  4.  
  5. @dataclass
  6. class Weather:
  7.     temperature: tuple
  8.     pressure: int
  9.     description: str
  10.     name: str
  11.  
  12. @dataclass
  13. class Temperature:
  14.     temp: float
  15.     feels_like: float
  16.     temp_min: float
  17.     temp_max: float
  18.  
  19. class WeatherDetails():
  20.  
  21.     def __init__(self, longitude, latitude, temperature = True, pressure = True, description = True, name = True, ans_of_req = True, weather = True, feels_like = True, temp_min = True, temp_max = True):
  22.      
  23.         self.longitude = longitude
  24.         self.latitude = latitude
  25.         self.temperature = temperature
  26.         self.pressure = pressure
  27.         self.description = description
  28.         self.name = name
  29.         self.ans_of_req = ans_of_req
  30.         self.weather = weather
  31.         self.feels_like = feels_like
  32.         self.temp_min = temp_min
  33.         self.temp_max = temp_max
  34.      
  35.     def weather_model(self):
  36.         req = requests.get("https://fcc-weather-api.glitch.me/api/current?", params={"lat" : self.latitude, "lon" : self.longitude})
  37.         self.ans_of_req = req.json()
  38.         self.temperature = self.ans_of_req["main"]["temp"]
  39.         self.pressure = self.ans_of_req["main"]["pressure"]
  40.         self.description = self.ans_of_req["weather"][0]["description"]
  41.         self.name = self.ans_of_req["name"]
  42.      
  43.         self.feels_like = self.ans_of_req["main"]["feels_like"]
  44.         self.temp_min = self.ans_of_req["main"]["temp_min"]
  45.         self.temp_max = self.ans_of_req["main"]["temp_max"]
  46.  
  47.      
  48.         self.weather = Weather((Temperature(self.temperature, self.feels_like, self.temp_min, self.temp_max)) , self.pressure, self.description, self.name)
  49.         print(self.weather)
  50.        
  51.        
  52.  
  53. obj = WeatherDetails(139, 35)
  54. print(obj.weather_model())
  55.  
  56.  
Advertisement
RAW Paste Data Copied
Advertisement