pyowm.abstractions package

Submodules

pyowm.abstractions.jsonparser module

Module containing an abstract base class for JSON OWM web API responses parsing

class pyowm.abstractions.jsonparser.JSONParser[source]

Bases: object

A global abstract class representing a JSON to object parser.

parse_JSON(JSON_string)[source]

Returns a proper object parsed from the input JSON_string. Subclasses know from their specific type which object is to be parsed and returned

Parameters:JSON_string (str) – a JSON text string
Returns:an object
Raises:ParseResponseError if it is impossible to find or parse the data needed to build the resulting object

pyowm.abstractions.linkedlist module

Module containing abstractions for defining a linked list data structure

class pyowm.abstractions.linkedlist.LinkedList[source]

Bases: object

An abstract class representing a Linked List data structure. Each element in the list should contain data and a reference to the next element in the list.

add(data)[source]

Adds a new node to the list. Implementations should decide where to put this new element (at the top, in the middle or at the end of the list) and should therefore update pointers to next elements and the list’s size.

Parameters:data (object) – the data to be inserted in the new list node
contains(data)[source]

Checks if the provided data is stored in at least one node of the list.

Parameters:data (object) – data of the seeked node
Returns:a boolean
index_of(data)[source]

Finds the position of a node in the list. The index of the first occurrence of the data is returned (indexes start at 0)

Parameters:data – data of the seeked node
Type:object
Returns:the int index or -1 if the node is not in the list
pop()[source]

Removes the last node from the list

Returns:the object data that was stored in the last node
remove(data)[source]

Removes a node from the list. Implementations should decide the policy to be followed when list items having the same data are to be removed, and should therefore update pointers to next elements and the list’s size.

Parameters:data (object) – the data to be removed in the new list node
size()[source]

Returns the number of elements in the list

Returns:an int

pyowm.abstractions.owm module

Module containing the abstract PyOWM library main entry point interface

class pyowm.abstractions.owm.OWM[source]

Bases: object

A global abstract class representing the OWM web API. Every query to the API is done programmatically via a concrete instance of this class. Subclasses should provide a method for every OWM web API endpoint.

get_API_key()[source]

Returns the OWM API key

Returns:the OWM API key string
get_API_version()[source]

Returns the currently supported OWM web API version

Returns:the OWM web API version string
get_version()[source]

Returns the current version of the PyOWM library

Returns:the current PyOWM library version string
is_API_online()[source]

Returns True if the OWM web API is currently online. A short timeout is used to determine API service availability.

Returns:bool
set_API_key(API_key)[source]

Updates the OWM API key

Parameters:API_key (str) – the new value for the OWM API key

pyowm.abstractions.owmcache module

Module containing the abstract PyOWM cache provider

class pyowm.abstractions.owmcache.OWMCache[source]

Bases: object

A global abstract class representing a caching provider which can be used to lookup the JSON responses to the most recently or most frequently issued OWM web API requests. The purpose of the caching mechanism is to avoid OWM web API requests and therefore network traffic: the implementations should be adapted to the time/memory requirements of the OWM data clients (i.e: a “slimmer” cache with lower lookup times but higher miss rates or a “fatter” cache with higher memory consumption and higher hit rates?). Subclasses should implement a proper caching algorithms bearing in mind that different weather data types may have different change rates: in example, observed weather can change very frequently while long-period weather forecasts change less frequently. External caching mechanisms (eg: memcached, redis, etc..) can be used by extending this class into a proper decorator for the correspondent Python bindings.

get(request_url)[source]

In case of a hit, returns the JSON string which represents the OWM web API response to the request being identified by a specific string URL.

Parameters:request_url (str) – an URL that uniquely identifies the request whose response is to be looked up
Returns:a JSON str in case of cache hit or None otherwise
set(request_url, response_json)[source]

Adds the specified response_json value to the cache using as a lookup key the request_url of the request that generated the value.

Parameters:
  • request_url (str) – the request URL
  • response_json (str) – the response JSON

Module contents