pyowm.commons package

Submodules

pyowm.commons.frontlinkedlist module

Module containing class related to the implementation of linked-list data structure

class pyowm.commons.frontlinkedlist.FrontLinkedList[source]

Bases: pyowm.abstractions.linkedlist.LinkedList

Implementation of a linked-list data structure. Insertions are performed at the front of the list and so are O(1) while deletions take O(n) because they can be performed against any of the linked list’s elements. Each element in the list is a LinkedListNode instance; after instantiation, the list contains no elements.

Parameters:
  • first_node (LinkedListNode) – reference to the first LinkedListNode element in the list
  • last_node (LinkedListNode) – reference to the last LinkedListNode element in the list
add(data)[source]

Adds a new data node to the front list. The provided data will be encapsulated into a new instance of LinkedListNode class and linked list pointers will be updated, as well as 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) – the seeked data
Returns:a boolean
first_node()[source]
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

remove(data)[source]

Removes a data node from the list. If the list contains more than one node having the same data that shall be removed, then the node having the first occurrency of the data is removed.

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
class pyowm.commons.frontlinkedlist.FrontLinkedListIterator(obj)[source]

Bases: object

Iterator over the LinkedListNode elements of a LinkedList class instance. The implementation keeps a copy of the iterated list so avoid concurrency problems when iterating over it. This can nevertheless be memory-consuming when big lists have to be iterated over.

Parameters:obj (object) – the iterable object (LinkedList)
Returns:a FrontLinkedListIterator instance
next()[source]

Compatibility for Python 2.x, delegates to function: __next__() Returns the next Weather item

Returns:the next Weather item
class pyowm.commons.frontlinkedlist.LinkedListNode(data, next_node)[source]

Class representing an element of the LinkedList

Parameters:
  • data (object) – the actual data that this node holds
  • next (LinkedListNode) – reference to the next LinkedListNode instance in the list
data()[source]

Returns the data in this node

Returns:an object
next()[source]

Returns the next LinkedListNode in the list

Returns:a LinkedListNode instance
update_next(linked_list_node)[source]
Parameters:linked_list_node (LinkedListNode) – the new reference to the next LinkedListNode element

pyowm.commons.weather_client module

Module containing classes for HTTP client/server interactions

class pyowm.commons.weather_client.WeatherHttpClient(API_key, cache, subscription_type='free')[source]

Bases: object

API_SUBSCRIPTION_SUBDOMAINS = {'pro': 'pro', 'free': 'api'}

An HTTP client class for the OWM web API. The class can leverage a caching mechanism

Parameters:
  • API_key (Unicode) – a Unicode object representing the OWM web API key
  • cache (an OWMCache concrete instance) – an OWMCache concrete instance that will be used to cache OWM web API responses.
  • subscription_type (str) – the type of OWM web API subscription to be wrapped. The value is used to pick the proper API subdomain for HTTP calls. Defaults to: ‘free’
call_API(API_endpoint_URL, params_dict, timeout=<object object>)[source]

Invokes a specific OWM web API endpoint URL, returning raw JSON data.

Parameters:
  • API_endpoint_URL (str) – the API endpoint to be invoked
  • params_dict (dict) – a dictionary containing the query parameters to be used in the HTTP request (given as key-value couples in the dict)
  • timeout (int) – how many seconds to wait for connection establishment (defaults to socket._GLOBAL_DEFAULT_TIMEOUT)
Returns:

a string containing raw JSON data

Raises:

APICallError

pyowm.commons.airpollution_client module

class pyowm.commons.airpollution_client.AirPollutionHttpClient(API_key, cache)[source]

Bases: object

An HTTP client class for the OWM Air Pollution web API. The class can leverage a caching mechanism

Parameters:
  • API_key (Unicode) – a Unicode object representing the OWM Air Pollution web API key
  • cache (an OWMCache concrete instance) – an OWMCache concrete instance that will be used to cache OWM Air Pollution web API responses.
get_coi(params_dict, timeout=<object object>)[source]

Invokes the CO Index endpoint

Parameters:
  • params_dict – dict of parameters
  • timeout (int) – how many seconds to wait for connection establishment (defaults to socket._GLOBAL_DEFAULT_TIMEOUT)
Returns:

a string containing raw JSON data

Raises:

ValueError, APICallError

get_no2(params_dict, timeout=<object object>)[source]

Invokes the NO2 Index endpoint

Parameters:
  • params_dict – dict of parameters
  • timeout (int) – how many seconds to wait for connection establishment (defaults to socket._GLOBAL_DEFAULT_TIMEOUT)
Returns:

a string containing raw JSON data

Raises:

ValueError, APICallError

get_o3(params_dict, timeout=<object object>)[source]

Invokes the O3 Index endpoint

Parameters:
  • params_dict – dict of parameters
  • timeout (int) – how many seconds to wait for connection establishment (defaults to socket._GLOBAL_DEFAULT_TIMEOUT)
Returns:

a string containing raw JSON data

Raises:

ValueError, APICallError

get_so2(params_dict, timeout=<object object>)[source]

Invokes the SO2 Index endpoint

Parameters:
  • params_dict – dict of parameters
  • timeout (int) – how many seconds to wait for connection establishment (defaults to socket._GLOBAL_DEFAULT_TIMEOUT)
Returns:

a string containing raw JSON data

Raises:

ValueError, APICallError

pyowm.commons.uv_client module

class pyowm.commons.uv_client.UltraVioletHttpClient(API_key, cache)[source]

Bases: object

An HTTP client class for the OWM UV web API. The class can leverage a caching mechanism

Parameters:
  • API_key (Unicode) – a Unicode object representing the OWM UV web API key
  • cache (an OWMCache concrete instance) – an OWMCache concrete instance that will be used to cache OWM UV web API responses.
get_uvi(params_dict, timeout=<object object>)[source]

Invokes the UV Index endpoint

Parameters:
  • params_dict – dict of parameters
  • timeout (int) – how many seconds to wait for connection establishment (defaults to socket._GLOBAL_DEFAULT_TIMEOUT)
Returns:

a string containing raw JSON data

Raises:

ValueError, APICallError

Module contents