How to use pywws - 10 common examples

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 / plot.py View on Github external
self.x_lo = self.x_hi - self.duration
        else:
            self.x_hi = self.hourly_data.before(datetime.max)
            if not self.x_hi:
                self.x_hi = datetime.utcnow()    # only if no hourly data
            self.x_hi += timezone.utcoffset(self.x_hi)
            if self.duration < timedelta(hours=6):
                # set end of graph to start of the next minute after last item
                self.x_hi += timedelta(seconds=55)
                self.x_hi = self.x_hi.replace(second=0)
            else:
                # set end of graph to start of the next hour after last item
                self.x_hi += timedelta(minutes=55)
                self.x_hi = self.x_hi.replace(minute=0, second=0)
            self.x_lo = self.x_hi - self.duration
        self.utcoffset = timezone.utcoffset(self.x_hi)
        # open gnuplot command file
        self.tmp_files = []
        cmd_file = os.path.join(self.work_dir, 'plot.cmd')
        self.tmp_files.append(cmd_file)
        of = codecs.open(cmd_file, 'w', encoding=self.encoding[0])
        # write gnuplot set up
        of.write('set encoding %s\n' % (self.encoding[1]))
        lcl = locale.getlocale()
        if lcl[0]:
            of.write('set locale "%s.%s"\n' % lcl)
        self.rows = self.get_default_rows()
        self.cols = (self.plot_count + self.rows - 1) // self.rows
        self.rows, self.cols = eval(self.graph.get_value(
            'layout', '%d, %d' % (self.rows, self.cols)))
        w, h = self.get_default_plot_size()
        w = w * self.cols
github jim-easterbrook / pywws / src / pywws / totwitter.py View on Github external
import argparse
    import inspect
    if argv is None:
        argv = sys.argv
    docstring = inspect.getdoc(sys.modules[__name__]).split('\n\n')
    parser = argparse.ArgumentParser(
        description=docstring[0], epilog=docstring[1])
    parser.add_argument('-r', '--register', action='store_true',
                        help='authorise pywws to post to your account')
    parser.add_argument('-v', '--verbose', action='count',
                        help='increase amount of reassuring messages')
    parser.add_argument('data_dir', help='root directory of the weather data')
    parser.add_argument('file', nargs='*', help='file to be uploaded')
    args = parser.parse_args(argv[1:])
    pywws.logger.setup_handler(args.verbose or 0)
    with pywws.storage.pywws_context(args.data_dir) as context:
        if args.register:
            twitter_auth(context.params)
            context.flush()
            return 0
        uploader = ToTwitter(context)
        for file in args.file:
            uploader.upload_file(file)
        uploader.stop()
    return 0
github jim-easterbrook / pywws / src / pywws / towebsite.py View on Github external
def main(argv=None):
    import argparse
    import inspect
    if argv is None:
        argv = sys.argv
    docstring = inspect.getdoc(sys.modules[__name__]).split('\n\n')
    parser = argparse.ArgumentParser(
        description=docstring[0], epilog=docstring[1])
    parser.add_argument('-v', '--verbose', action='count',
                        help='increase amount of reassuring messages')
    parser.add_argument('data_dir', help='root directory of the weather data')
    parser.add_argument('file', nargs='+', help='file to be uploaded')
    args = parser.parse_args(argv[1:])
    pywws.logger.setup_handler(args.verbose or 0)
    with pywws.storage.pywws_context(args.data_dir) as context:
        uploader = ToWebSite(context)
        uploader.upload(args.file)
        uploader.stop()
    return 0
github jim-easterbrook / pywws / src / pywws / totwitter.py View on Github external
def main(argv=None):
    import argparse
    import inspect
    if argv is None:
        argv = sys.argv
    docstring = inspect.getdoc(sys.modules[__name__]).split('\n\n')
    parser = argparse.ArgumentParser(
        description=docstring[0], epilog=docstring[1])
    parser.add_argument('-r', '--register', action='store_true',
                        help='authorise pywws to post to your account')
    parser.add_argument('-v', '--verbose', action='count',
                        help='increase amount of reassuring messages')
    parser.add_argument('data_dir', help='root directory of the weather data')
    parser.add_argument('file', nargs='*', help='file to be uploaded')
    args = parser.parse_args(argv[1:])
    pywws.logger.setup_handler(args.verbose or 0)
    with pywws.storage.pywws_context(args.data_dir) as context:
        if args.register:
            twitter_auth(context.params)
            context.flush()
            return 0
        uploader = ToTwitter(context)
        for file in args.file:
            uploader.upload_file(file)
        uploader.stop()
    return 0
github jim-easterbrook / pywws / src / pywws / service / pwsweather.py View on Github external
try:
            rsp = session.get(
                'http://www.pwsweather.com/pwsupdate/pwsupdate.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 / 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 / examples / modules / aws_api_gw_service.py View on Github external
for header in literal_eval(self.params['http headers']):
                    session.headers.update({header[0]: header[1]})
            rsp = session.get(self.params['api url'], 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)
        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 / 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 / ftp.py View on Github external
mode = 'r'
        else:
            mode = 'rb'
        try:
            with open(path, mode) as f:
                if text_file:
                    session.storlines('STOR %s' % (target), f)
                else:
                    session.storbinary('STOR %s' % (target), f)
        except Exception as ex:
            return False, repr(ex)
        return True, 'OK'


if __name__ == "__main__":
    sys.exit(pywws.service.main(ToService))