How to use the pywws.service function in pywws

To help you get started, we’ve selected a few pywws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jim-easterbrook / pywws / src / pywws / service / temperaturnu.py View on Github external
def upload_data(self, session, prepared_data={}):
        try:
            rsp = session.get('http://www.temperatur.nu/rapportera.php',
                              params=prepared_data, timeout=60)
        except Exception as ex:
            return False, repr(ex)
        if rsp.status_code != 200:
            return False, 'http status: {:d}'.format(rsp.status_code)
        text = rsp.text.strip()
        if text:
            return True, 'server response "{:s}"'.format(text)
        return True, 'OK'


if __name__ == "__main__":
    sys.exit(pywws.service.main(ToService))
github jim-easterbrook / pywws / src / pywws / service / copy.py View on Github external
    @contextmanager
    def session(self):
        yield None

    def upload_file(self, session, path):
        try:
            if not os.path.isdir(self.params['directory']):
                os.makedirs(self.params['directory'])
            shutil.copy(path, self.params['directory'])
        except Exception as ex:
            return False, repr(ex)
        return True, 'OK'


if __name__ == "__main__":
    sys.exit(pywws.service.main(ToService))
github jim-easterbrook / pywws / src / pywws / service / metoffice.py View on Github external
params=prepared_data, timeout=60)
        except Exception as ex:
            return False, repr(ex)
        if rsp.status_code == 429:
            # UK Met Office server uses 429 to signal duplicate data
            return True, 'repeated data {:s}'.format(prepared_data['dateutc'])
        if rsp.status_code != 200:
            return False, 'http status: {:d}'.format(rsp.status_code)
        rsp = rsp.json()
        if rsp:
            return True, 'server response "{!r}"'.format(rsp)
        return True, 'OK'


if __name__ == "__main__":
    sys.exit(pywws.service.main(ToService))
github jim-easterbrook / pywws / src / pywws / service / temperaturnu.py View on Github external
from contextlib import contextmanager
from datetime import timedelta
import logging
import os
import sys

import requests

import pywws.service

__docformat__ = "restructuredtext en"
service_name = os.path.splitext(os.path.basename(__file__))[0]
logger = logging.getLogger(__name__)


class ToService(pywws.service.LiveDataService):
    config = {'hash': ('', True, 'hash')}
    logger = logger
    service_name = service_name
    template = "#live##temp_out \"'t': '%.1f',\"#"

    @contextmanager
    def session(self):
        with requests.Session() as session:
            yield session

    def valid_data(self, data):
        return data['temp_out'] is not None

    def upload_data(self, session, prepared_data={}):
        try:
            rsp = session.get('http://www.temperatur.nu/rapportera.php',
github jim-easterbrook / pywws / src / pywws / service / mastodon.py View on Github external
import codecs
from contextlib import contextmanager
import logging
import os
import sys

from mastodon import Mastodon

import pywws.service

__docformat__ = "restructuredtext en"
service_name = os.path.splitext(os.path.basename(__file__))[0]
logger = logging.getLogger(__name__)


class ToService(pywws.service.FileService):
    config = {
        'handle'      : ('',   True, None),
        'access_token': (None, True, None),
        }
    logger = logger
    service_name = service_name

    def __init__(self, context, check_params=True):
        super(ToService, self).__init__(context, check_params)
        # get default character encoding of template output
        self.encoding = context.params.get(
            'config', 'template encoding', 'iso-8859-1')

    @contextmanager
    def session(self):
        yield Mastodon(access_token=self.params['access_token'],
github jim-easterbrook / pywws / src / pywws / service / copy.py View on Github external
from contextlib import contextmanager
from datetime import timedelta
import logging
import os
import shutil
import sys

import pywws.service

__docformat__ = "restructuredtext en"
service_name = os.path.splitext(os.path.basename(__file__))[0]
logger = logging.getLogger(__name__)


class ToService(pywws.service.FileService):
    config = {'directory'  : ('', True,  None)}
    logger = logger
    service_name = service_name

    @contextmanager
    def session(self):
        yield None

    def upload_file(self, session, path):
        try:
            if not os.path.isdir(self.params['directory']):
                os.makedirs(self.params['directory'])
            shutil.copy(path, self.params['directory'])
        except Exception as ex:
            return False, repr(ex)
        return True, 'OK'