Package: weatherapi-forked
Getting startedIntroductionWeatherAPI.com provides access to weather and geo data via a JSON/XML restful API. It allows developers to create desktop, web and mobile applications using this data very easy.We provide following data through our API:Real-time weather10 day weather forecastAstronomyTime zoneLocation dataSearch or Autocomplete APINEW: Historical weatherGetting StartedYou need tosignupand then you can find your API key underyour account, and start using API right away!If you find any features missing or have any suggestions, pleasecontact us.AuthenticationAPI access to the data is protected by an API key. If at anytime, you find the API key has become vulnerable, please regenerate the key using Regenerate button next to the API key.Authentication to the WeatherAPI.com API is provided by passing your API key as request parameter through an API .key parameterkey=YOUR_API_KEYHow to BuildYou must have Python2 >=2.7.9or Python3 >=3.4installed on your system to install and run this SDK. This SDK package depends on other Python packages like nose, jsonpickle etc.
These dependencies are defined in therequirements.txtfile that comes with the SDK.
To resolve these dependencies, you can use the PIP Dependency manager. Install it by following steps athttps://pip.pypa.io/en/stable/installing/.Python and PIP executables should be defined in your PATH. Open command prompt and typepip --version.
This should display the version of the PIP Dependency Manager installed if your installation was successful and the paths are properly defined.Using command line, navigate to the directory containing the generated files (includingrequirements.txt) for the SDK.Run the commandpip install -r requirements.txt. This should install all the required dependencies.How to UseThe following section explains how to use the Weatherapi SDK package in a new project.1. Open Project in an IDEOpen up a Python IDE like PyCharm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.Click onOpenin PyCharm to browse to your generated SDK directory and then clickOK.The project files will be displayed in the side bar as follows:2. Add a new Test ProjectCreate a new directory by right clicking on the solution name as shown below:Name the directory as "test"Add a python file to this project with the name "testsdk"Name it "testsdk"In your python file you will be required to import the generated python library using the following code linesfromweatherapi.weatherapi_clientimportWeatherapiClientAfter this you can write code to instantiate an API client object, get a controller object and  make API calls. Sample code is given in the subsequent sections.3. Run the Test ProjectTo run the file within your test project, right click on your Python file inside your Test project and click onRunHow to TestYou can test the generated SDK and the server with automatically generated test
cases. unittest is used as the testing framework and nose is used as the test
runner. You can run the tests as follows:From terminal/cmd navigate to the root directory of the SDK.Invokepip install -r test-requirements.txtInvokenosetestsInitializationAuthenticationIn order to setup authentication and initialization of the API client, you need the following information.ParameterDescriptionkeyTODO: add a descriptionAPI client can be initialized as following.# Configuration parameters and credentialskey='key'client=WeatherapiClient(key)Class ReferenceList of ControllersAPIsControllerAPIsControllerGet controller instanceAn instance of theAPIsControllerclass can be accessed from the API Client.ap_is_controller=client.ap_isget_realtime_weatherCurrent weather or realtime weather API method allows a user to get up to date current weather information in json and xml. The data is returned as a Current Object.Current object contains current or realtime weather information for a given city.defget_realtime_weather(self,q,lang=None)ParametersParameterTagsDescriptionqRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visitrequest parameter sectionto learn more.langOptionalReturns 'condition:text' field in API in the desired language. Visitrequest parameter sectionto check 'lang-code'.Example Usageq='q'lang='lang'result=ap_is_controller.get_realtime_weather(q,lang)ErrorsError CodeError Description400Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error.401Error code 1002: API key not provided.Error code 2006: API key provided is invalid403Error code 2007: API key has exceeded calls per month quota.Error code 2008: API key has been disabled.get_forecast_weatherForecast weather API method returns upto next 10 day weather forecast and weather alert as json. The data is returned as a Forecast Object.Forecast object contains astronomy data, day weather forecast and hourly interval weather information for a given city.defget_forecast_weather(self,q,days,dt=None,unixdt=None,hour=None,lang=None)ParametersParameterTagsDescriptionqRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visitrequest parameter sectionto learn more.daysRequiredNumber of days of weather forecast. Value ranges from 1 to 10dtOptionalDate should be between today and next 10 day in yyyy-MM-dd formatunixdtOptionalPlease either pass 'dt' or 'unixdt' and not both in same request.unixdt should be between today and next 10 day in Unix formathourOptionalMust be in 24 hour. For example 5 pm should be hour=17, 6 am as hour=6langOptionalReturns 'condition:text' field in API in the desired language. Visitrequest parameter sectionto check 'lang-code'.Example Usageq='q'days=30dt=datetime.now()unixdt=30hour=30lang='lang'result=ap_is_controller.get_forecast_weather(q,days,dt,unixdt,hour,lang)ErrorsError CodeError Description400Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error.401Error code 1002: API key not provided.Error code 2006: API key provided is invalid403Error code 2007: API key has exceeded calls per month quota.Error code 2008: API key has been disabled.get_history_weatherHistory weather API method returns historical weather for a date on or after 1st Jan, 2015 as json. The data is returned as a Forecast Object.defget_history_weather(self,q,dt,unixdt=None,end_dt=None,unixend_dt=None,hour=None,lang=None)ParametersParameterTagsDescriptionqRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visitrequest parameter sectionto learn more.dtRequiredDate on or after 1st Jan, 2015 in yyyy-MM-dd formatunixdtOptionalPlease either pass 'dt' or 'unixdt' and not both in same request.unixdt should be on or after 1st Jan, 2015 in Unix formatendDtOptionalDate on or after 1st Jan, 2015 in yyyy-MM-dd format'end_dt' should be greater than 'dt' parameter and difference should not be more than 30 days between the two dates.unixendDtOptionalDate on or after 1st Jan, 2015 in Unix Timestamp formatunixend_dt has same restriction as 'end_dt' parameter. Please either pass 'end_dt' or 'unixend_dt' and not both in same request. e.g.: unixend_dt=1490227200hourOptionalMust be in 24 hour. For example 5 pm should be hour=17, 6 am as hour=6langOptionalReturns 'condition:text' field in API in the desired language. Visitrequest parameter sectionto check 'lang-code'.Example Usageq='q'dt=datetime.now()unixdt=30end_dt=datetime.now()unixend_dt=30hour=30lang='lang'result=ap_is_controller.get_history_weather(q,dt,unixdt,end_dt,unixend_dt,hour,lang)ErrorsError CodeError Description400Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error.401Error code 1002: API key not provided.Error code 2006: API key provided is invalid403Error code 2007: API key has exceeded calls per month quota.Error code 2008: API key has been disabled.search_autocomplete_weatherWeatherAPI.com Search or Autocomplete API returns matching cities and towns as an array of Location object.defsearch_autocomplete_weather(self,q)ParametersParameterTagsDescriptionqRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visitrequest parameter sectionto learn more.Example Usageq='q'result=ap_is_controller.search_autocomplete_weather(q)ErrorsError CodeError Description400Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error.401Error code 1002: API key not provided.Error code 2006: API key provided is invalid403Error code 2007: API key has exceeded calls per month quota.Error code 2008: API key has been disabled.get_ip_lookupIP Lookup API method allows a user to get up to date information for an IP address.defget_ip_lookup(self,q)ParametersParameterTagsDescriptionqRequiredPass IP address.Example Usageq='q'result=ap_is_controller.get_ip_lookup(q)ErrorsError CodeError Description400Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error.401Error code 1002: API key not provided.Error code 2006: API key provided is invalid403Error code 2007: API key has exceeded calls per month quota.Error code 2008: API key has been disabled.get_time_zoneReturn Location Objectdefget_time_zone(self,q)ParametersParameterTagsDescriptionqRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visitrequest parameter sectionto learn more.Example Usageq='q'result=ap_is_controller.get_time_zone(q)ErrorsError CodeError Description400Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error.401Error code 1002: API key not provided.Error code 2006: API key provided is invalid403Error code 2007: API key has exceeded calls per month quota.Error code 2008: API key has been disabled.get_astronomyReturn Location and Astronomy Objectdefget_astronomy(self,q,dt)ParametersParameterTagsDescriptionqRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visitrequest parameter sectionto learn more.dtRequiredDate on or after 1st Jan, 2015 in yyyy-MM-dd formatExample Usageq='q'dt=datetime.now()result=ap_is_controller.get_astronomy(q,dt)ErrorsError CodeError Description400Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error.401Error code 1002: API key not provided.Error code 2006: API key provided is invalid403Error code 2007: API key has exceeded calls per month quota.Error code 2008: API key has been disabled.Back to List of Controllers