Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

weatherapi-forked

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

weatherapi-forked

Python client library for Weather API

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

Getting started

Introduction

WeatherAPI.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 weather

  • 10 day weather forecast

  • Astronomy

  • Time zone

  • Location data

  • Search or Autocomplete API

  • NEW: Historical weather

Getting Started

You need to signup and then you can find your API key under your account, and start using API right away!

If you find any features missing or have any suggestions, please contact us.

Authentication

API 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 parameter

key=YOUR_API_KEY

How to Build

You must have Python 2 >=2.7.9 or Python 3 >=3.4 installed 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 the requirements.txt file that comes with the SDK. To resolve these dependencies, you can use the PIP Dependency manager. Install it by following steps at https://pip.pypa.io/en/stable/installing/.

Python and PIP executables should be defined in your PATH. Open command prompt and type pip --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 (including requirements.txt) for the SDK.
  • Run the command pip install -r requirements.txt. This should install all the required dependencies.

Building SDK - Step 1

How to Use

The following section explains how to use the Weatherapi SDK package in a new project.

1. Open Project in an IDE

Open up a Python IDE like PyCharm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.

Open project in PyCharm - Step 1

Click on Open in PyCharm to browse to your generated SDK directory and then click OK.

Open project in PyCharm - Step 2

The project files will be displayed in the side bar as follows:

Open project in PyCharm - Step 3

2. Add a new Test Project

Create a new directory by right clicking on the solution name as shown below:

Add a new project in PyCharm - Step 1

Name the directory as "test"

Add a new project in PyCharm - Step 2

Add a python file to this project with the name "testsdk"

Add a new project in PyCharm - Step 3

Name it "testsdk"

Add a new project in PyCharm - Step 4

In your python file you will be required to import the generated python library using the following code lines

from weatherapi.weatherapi_client import WeatherapiClient

Add a new project in PyCharm - Step 4

After 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 Project

To run the file within your test project, right click on your Python file inside your Test project and click on Run

Run Test Project - Step 1

How to Test

You 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:

  1. From terminal/cmd navigate to the root directory of the SDK.
  2. Invoke pip install -r test-requirements.txt
  3. Invoke nosetests

Initialization

Authentication

In order to setup authentication and initialization of the API client, you need the following information.

ParameterDescription
keyTODO: add a description

API client can be initialized as following.

# Configuration parameters and credentials
key = 'key'

client = WeatherapiClient(key)

Class Reference

List of Controllers

Class: APIsController

Get controller instance

An instance of the APIsController class can be accessed from the API Client.

 ap_is_controller = client.ap_is

Method: get_realtime_weather

Current 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.

def get_realtime_weather(self,
                             q,
                             lang=None)
Parameters
ParameterTagsDescription
qRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more.
langOptionalReturns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'.
Example Usage
q = 'q'
lang = 'lang'

result = ap_is_controller.get_realtime_weather(q, lang)

Errors
Error CodeError Description
400Error 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 invalid
403Error code 2007: API key has exceeded calls per month quota.
Error code 2008: API key has been disabled.

Method: get_forecast_weather

Forecast 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.

def get_forecast_weather(self,
                             q,
                             days,
                             dt=None,
                             unixdt=None,
                             hour=None,
                             lang=None)
Parameters
ParameterTagsDescription
qRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more.
daysRequiredNumber of days of weather forecast. Value ranges from 1 to 10
dtOptionalDate should be between today and next 10 day in yyyy-MM-dd format
unixdtOptionalPlease either pass 'dt' or 'unixdt' and not both in same request.
unixdt should be between today and next 10 day in Unix format
hourOptionalMust be in 24 hour. For example 5 pm should be hour=17, 6 am as hour=6
langOptionalReturns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'.
Example Usage
q = 'q'
days = 30
dt = datetime.now()
unixdt = 30
hour = 30
lang = 'lang'

result = ap_is_controller.get_forecast_weather(q, days, dt, unixdt, hour, lang)

Errors
Error CodeError Description
400Error 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 invalid
403Error code 2007: API key has exceeded calls per month quota.
Error code 2008: API key has been disabled.

Method: get_history_weather

History 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.

def get_history_weather(self,
                            q,
                            dt,
                            unixdt=None,
                            end_dt=None,
                            unixend_dt=None,
                            hour=None,
                            lang=None)
Parameters
ParameterTagsDescription
qRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more.
dtRequiredDate on or after 1st Jan, 2015 in yyyy-MM-dd format
unixdtOptionalPlease either pass 'dt' or 'unixdt' and not both in same request.
unixdt should be on or after 1st Jan, 2015 in Unix format
endDtOptionalDate 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 format
unixend_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=1490227200
hourOptionalMust be in 24 hour. For example 5 pm should be hour=17, 6 am as hour=6
langOptionalReturns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'.
Example Usage
q = 'q'
dt = datetime.now()
unixdt = 30
end_dt = datetime.now()
unixend_dt = 30
hour = 30
lang = 'lang'

result = ap_is_controller.get_history_weather(q, dt, unixdt, end_dt, unixend_dt, hour, lang)

Errors
Error CodeError Description
400Error 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 invalid
403Error code 2007: API key has exceeded calls per month quota.
Error code 2008: API key has been disabled.

Method: search_autocomplete_weather

WeatherAPI.com Search or Autocomplete API returns matching cities and towns as an array of Location object.

def search_autocomplete_weather(self,
                                    q)
Parameters
ParameterTagsDescription
qRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more.
Example Usage
q = 'q'

result = ap_is_controller.search_autocomplete_weather(q)

Errors
Error CodeError Description
400Error 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 invalid
403Error code 2007: API key has exceeded calls per month quota.
Error code 2008: API key has been disabled.

Method: get_ip_lookup

IP Lookup API method allows a user to get up to date information for an IP address.

def get_ip_lookup(self,
                      q)
Parameters
ParameterTagsDescription
qRequiredPass IP address.
Example Usage
q = 'q'

result = ap_is_controller.get_ip_lookup(q)

Errors
Error CodeError Description
400Error 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 invalid
403Error code 2007: API key has exceeded calls per month quota.
Error code 2008: API key has been disabled.

Method: get_time_zone

Return Location Object

def get_time_zone(self,
                      q)
Parameters
ParameterTagsDescription
qRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more.
Example Usage
q = 'q'

result = ap_is_controller.get_time_zone(q)

Errors
Error CodeError Description
400Error 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 invalid
403Error code 2007: API key has exceeded calls per month quota.
Error code 2008: API key has been disabled.

Method: get_astronomy

Return Location and Astronomy Object

def get_astronomy(self,
                      q,
                      dt)
Parameters
ParameterTagsDescription
qRequiredPass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more.
dtRequiredDate on or after 1st Jan, 2015 in yyyy-MM-dd format
Example Usage
q = 'q'
dt = datetime.now()

result = ap_is_controller.get_astronomy(q, dt)

Errors
Error CodeError Description
400Error 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 invalid
403Error code 2007: API key has exceeded calls per month quota.
Error code 2008: API key has been disabled.

Back to List of Controllers

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc