This module is used to get or print the weather deatils using open weather API easily
install module using pip command
pip install easyOpenWeather==0.3
from easyOpenWeather import module
Then make a object instance of WeatherDataClass
obj = module.WeatherDataClass()
Now you need to at least set the city name
obj.setCityName("london")
Module uses the built api key , as in built api is used by many people it may be sometimes busy and produce error , to be on safe side set your own api key :
obj.setApiKey("fe82651e60**************9aa7e17")
To know how to get your own api key from open weather click here
Now you need to pass a list containing attributes for which you need weather data
List Attributes -
- temp -> for temperature in kelvin
- tempInC -> for temperature in celcius
- tempInF -> for temperature in f
- tempMin -> for min temp - unit is decided from above
- tempMax -> for max temp - unit is decided from above
- pressure -> for pressure
- humidity -> for humidity
- wind speed -> for wind speed
- wind direction -> for wind direction
- description -> for description - like clear sky etc
To set list Use -
listPass = ["tempInC" , "tempMin" , "tempMax" , "pressure" , "humidity" , "windSpeed" , "windDirection" , "clouds" , "description"]
obj.setList(listPass)
To get data in dictionary format -
print(obj.getInfo())
The function will return a dictionary.
Sample dictionary that you will get for listPass = ["tempInC" , "tempMin" , "tempMax" , "pressure" , "humidity" , "windSpeed" , "windDirection" , "clouds" , "description"] =
{'tempInC': 11.01, 'tempMin': 10.71, 'tempMax': 11.82, 'pressure': 998, 'humidity': 53, 'windSpeed': 8.7, 'windDirection': 260, 'clouds': 9, 'description': 'clear sky'}
This module also include a inbuilt function to directly print the data in a tabular format
obj.printData()
Other methods -
-
obj.setStringKey(stringKey) - To set custom api url. Default url - https://api.openweathermap.org/data/2.5/weather?q=
Some getters -
-
obj.getStringKey()
-
obj.getApiKey()
-
obj.getCityName()
from easyOpenWeather import module
obj = module.WeatherDataClass()
obj.setCityName("london")
listPass = ["tempInC" , "tempMin" , "tempMax" , "pressure" , "humidity" , "windSpeed" , "windDirection" , "clouds" , "description"]
obj.setList(listPass)
obj.printData()
# output
# Weather Query Data Received
# --------------- ---------------
# tempInC 6.45
# tempMin 5.71
# tempMax 7.15
# pressure 1000
# humidity 81
# windSpeed 2.6
# windDirection 100
# clouds 75
# description broken clouds