diff --git a/platypush/backend/http/poll/__init__.py b/platypush/backend/http/poll/__init__.py new file mode 100644 index 00000000..217b3e6c --- /dev/null +++ b/platypush/backend/http/poll/__init__.py @@ -0,0 +1,50 @@ +import json +import requests + +from threading import Thread + +from platypush.message.response import Response + +from .. import Backend + + +class HttpPollBackend(Backend): + """ + This backend will poll multiple HTTP endpoints/services and return events + the bus whenever something new happened. Example configuration: + + backend.http.poll: + services: + - + type: platypush.backend.http.service.ota.booking.GetReservations + args: + token: YOUR_TOKEN + poll_seconds: 10 # Check for updates on this endpoint every 10 seconds + limit: 5 # Return the first 5 (new) results (default: all) + """ + + def __init__(self, services, *args, **kwargs): + """ + Params: + services -- List/iterable of HttpService objects + """ + + super().__init__(*args, **kwargs) + self.services = services + + + def run(self): + super().run() + + def send_message(self, msg): + pass + + def on_stop(self): + pass + + def stop(self): + super().stop() + + +# vim:sw=4:ts=4:et: + diff --git a/platypush/config/__init__.py b/platypush/config/__init__.py index dc7e3f68..9be7fa3e 100644 --- a/platypush/config/__init__.py +++ b/platypush/config/__init__.py @@ -1,3 +1,4 @@ +import errno import logging import os import socket @@ -30,6 +31,8 @@ class Config(object): os.path.join(os.sep, 'etc', 'platypush', 'config.yaml'), ] + _workdir_location = os.path.join(os.environ['HOME'], '.local', 'share', 'platypush') + def __init__(self, cfgfile=None): """ Constructor. Always use the class as a singleton (i.e. through @@ -49,6 +52,10 @@ class Config(object): self._cfgfile = cfgfile self._config = self._read_config_file(self._cfgfile) + if 'workdir' not in self._config: + self._config['workdir'] = self._workdir_location + mkdir_p(self._config['workdir']) + if 'logging' not in self._config: self._config['logging'] = logging.INFO else: @@ -182,5 +189,13 @@ class Config(object): if _default_config_instance is None: _default_config_instance = Config() _default_config_instance._config[key] = key + +def mkdir_p(path): + try: os.makedirs(path) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(path): pass + else: raise + + # vim:sw=4:ts=4:et: