From 81f01e08265408109ce44860a5c12b8967d9fdb0 Mon Sep 17 00:00:00 2001 From: "Andris Jansons (jansonsa)" Date: Mon, 13 Nov 2017 17:17:05 +0000 Subject: [PATCH] Add files via upload --- pyowm/__init__.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++ pyowm/constants.py | 7 ++++++ 2 files changed, 66 insertions(+) create mode 100644 pyowm/__init__.py create mode 100644 pyowm/constants.py diff --git a/pyowm/__init__.py b/pyowm/__init__.py new file mode 100644 index 0000000..02b4fcc --- /dev/null +++ b/pyowm/__init__.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +The PyOWM init file + +**Author**: Claudio Sparpaglione, @csparpa + +**Platform**: platform independent + +""" + +from pyowm import constants +from pyowm.utils import timeutils # Convenience import + + +def OWM(API_key=constants.DEFAULT_API_KEY, version=constants.LATEST_OWM_API_VERSION, + config_module=None, language=None, subscription_type=None): + """ + A parametrized factory method returning a global OWM instance that + represents the desired OWM web API version (or the currently supported one + if no version number is specified) + + :param API_key: the OWM web API key (defaults to a test value) + :type API_key: str + :param version: the OWM web API version. Defaults to ``None``, which means + use the latest web API version + :type version: str + :param config_module: the Python path of the configuration module you want + to provide for instantiating the library. Defaults to ``None``, which + means use the default configuration values for the web API version + support you are currently requesting. Please be aware that malformed + user-defined configuration modules can lead to unwanted behaviour! + :type config_module: str (eg: 'mypackage.mysubpackage.myconfigmodule') + :param language: the language in which you want text results to be returned. + It's a two-characters string, eg: "en", "ru", "it". Defaults to: + ``None``, which means use the default language. + :type language: str + :param subscription_type: the type of OWM web API subscription to be wrapped. + Can be 'free' (free subscription) or 'pro' (paid subscription), + Defaults to: 'free' + :type subscription_type: str + :returns: an instance of a proper *OWM* subclass + :raises: *ValueError* when unsupported OWM API versions are provided + """ + if version == '2.5': + if config_module is None: + config_module = "pyowm.webapi25.configuration25" + cfg_module = __import__(config_module, fromlist=['']) + from pyowm.webapi25.owm25 import OWM25 + if language is None: + language = cfg_module.language + if subscription_type is None: + subscription_type = cfg_module.API_SUBSCRIPTION_TYPE + if subscription_type not in ['free', 'pro']: + subscription_type = 'free' + return OWM25(cfg_module.parsers, API_key, cfg_module.cache, + language, subscription_type) + raise ValueError("Unsupported OWM web API version") diff --git a/pyowm/constants.py b/pyowm/constants.py new file mode 100644 index 0000000..f0d8c02 --- /dev/null +++ b/pyowm/constants.py @@ -0,0 +1,7 @@ +""" +Constants for the PyOWM library +""" + +PYOWM_VERSION = '2.7.1' +LATEST_OWM_API_VERSION = '2.5' +DEFAULT_API_KEY = 'b1b15e88fa797225412429c1c50c122a' \ No newline at end of file