diff --git a/weatherkit/current_weather.py b/weatherkit/current_weather.py index 6f9da95..24c122d 100644 --- a/weatherkit/current_weather.py +++ b/weatherkit/current_weather.py @@ -60,6 +60,15 @@ def __init__(self, lat,lon=None): def temperature(self,units='metric'): ''' This method is used to get the current temperature of the city. + + Parameters: + units: str + The unit of the temperature. Default is 'metric'. + 'metric' for Celsius and 'imperical' for Fahrenheit. + + Returns: + float + The current temperature of the city. ''' if self.lat and self.lon: url = "https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}¤t=temperature_2m".format(self.lat, self.lon) @@ -76,6 +85,10 @@ def temperature(self,units='metric'): def humidity(self): ''' This method is used to get the current humidity of the city. + + Returns: + float + The current humidity of the city. ''' if self.lat and self.lon: url = "https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}¤t=relative_humidity_2m".format(self.lat, self.lon) @@ -89,6 +102,14 @@ def humidity(self): def precipitation(self,units='metric'): ''' This method is used to get the current precipitation of the city. + Parameters: + units: str + The unit of the temperature. Default is 'metric'. + 'metric' for Celsius and 'imperical' for Fahrenheit. + + Returns: + float + The current precipitation of the city. ''' if self.lat and self.lon: url = "https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}¤t=precipitation".format(self.lat, self.lon) @@ -104,6 +125,9 @@ def precipitation(self,units='metric'): def weather_code(self): ''' This method is used to get the current weather code of the city. + Returns: + int + The current weather code of the city. ''' if self.lat and self.lon: url = "https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}¤t=weather_code".format(self.lat, self.lon) @@ -112,5 +136,28 @@ def weather_code(self): return data["current"]["weather_code"] except Exception as e: return "Error fetching weather data:", e + else: + return "Invalid Latitude or Longitude" + def wind_speed(self,units='metric'): + ''' + This method is used to get the current wind speed of the city. + Parameters: + units: str + The unit of the temperature. Default is 'metric'. + 'metric' for Celsius and 'imperical' for Fahrenheit. + + Returns: + tuple(float windspeed,float direction in deg) + The current wind speed and wind direction of the city. + ''' + if self.lat and self.lon: + url = "https://api.open-meteo.com/v1/forecast?latitude={}&longitude={}¤t=wind_speed_10m,wind_direction_10m".format(self.lat, self.lon) + if units == 'imperical': + url = url + "&wind_speed_unit=mph" + try: + data = requests.get(url).json() + return data["current"]["wind_speed_10m"], data["current"]["wind_direction_10m"] + except Exception as e: + return "Error fetching weather data:", e else: return "Invalid Latitude or Longitude" \ No newline at end of file