GithubHelp home page GithubHelp logo

csparpa / pyowm-cache-adapters Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 148 KB

A set of simple Python adapters allowing the PyOWM library to leverage external cache systems

License: MIT License

Python 100.00%

pyowm-cache-adapters's Introduction

pyowm-cache-adapters

A set of simple draft adapters allowing the PyOWM library to leverage external cache systems. The code relies on the Python bindings for the adapted system.

Supported cache systems

More to come...

License

MIT license

Installation

  1. Of course, you need to install the PyOWM library before :-) Use pip
  2. Install the Python bindings for the cache system/s you need to adapt:
  3. Download the adapters package
  4. Place it somewhere you can reach via your PYTHONPATH variable (the PyOWM installation folder is OK)

Wiring

There are two ways...

The easy one

  1. Wire the adapters into a configuration module that you setup and put in a location reachable from your PYTHONPATH. Eg: say your config file is mypyowmconfig/myconfig.py and mypyowmconfig is somewhere in your PYTHONPATH:

    # Content of your own PyOWM config module
    from pyowm-cache-adapters import redis_adapter  # This is where you installed the adapters
    cache = nullcache.RedisAdapter()
    # [...] (other config values)
    
  2. Instantiate the library injecting a reference to your own config module. Eg:

    import pyowm
    owm = pyowm.OWM(None, None, 'mypyowmconfig.myconfig')  # This loads the config values from your module
    

    More about PyOWM config module on the PyOWM wiki.

The difficult one

  1. Find the configurationXX.py file which is specific for the web API version you are currently using. This will likely be in /usr/local/lib/python2.6/dist-packages/pyowm/webapi25/config25.py for Unix-like envs or in C:\Python27\Lib\site-packages\pyowm\webapi25\config25.py for Windows envs.

  2. Open the file and spot this line:

    # Cache provider to be used
    cache = NullCache()

    and change it accordingly to the adapter you need. In example, for Memcached:

    # Cache provider to be used
    # cache = NullCache()  # <--- comment/remove this line
    from pyowm_cache_adapter.memcached_adapter import MemcachedAdapter
    cache = MemcachedAdapter( [... parameters ...] )

    (be careful not to miss the import statement)

Modifying

The provided adapters are just intended to be drafts: modify them accordingly to your application-specific needs.

There's only one thing that you must bear in mind: each adapter must subclass the the pyowm.abstractions.owmcache.OWMCache abstract class for it to work into the PyOWM library.

Bugs

Please signal any bugs you may encounter.

pyowm-cache-adapters's People

Contributors

csparpa avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.