How to use the pywws.storage 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 / livelog.py View on Github external
def live_log(data_dir):
    # set up signal handlers
    signal.signal(signal.SIGHUP, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)
    with pywws.storage.pywws_context(data_dir, live_logging=True) as context:
        # localise application
        pywws.localisation.set_application_language(context.params)
        # create a DataLogger object
        datalogger = pywws.logdata.DataLogger(context)
        # create a RegularTasks object
        tasks = pywws.regulartasks.RegularTasks(context)
        try:
            # fetch and process any new logged data
            datalogger.log_data()
            pywws.process.process_data(context)
            # get live data
            for data, logged in datalogger.live_data(
                                    logged_only=(not tasks.has_live_tasks())):
                if logged:
                    # process new data
                    pywws.process.process_data(context)
github jim-easterbrook / pywws / src / pywws / forecast.py View on Github external
except getopt.error as msg:
        print('Error: %s\n' % msg, file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 1
    # process options
    for o, a in opts:
        if o in ('-h', '--help'):
            print(__usage__.strip())
            return 0
    # check arguments
    if len(args) != 1:
        print("Error: 1 argument required", file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 2
    data_dir = args[0]
    with pywws.storage.pywws_context(data_dir) as context:
        params = context.params
        pywws.localisation.set_application_language(params)
        hourly_data = context.hourly_data
        idx = hourly_data.before(datetime.max)
        print('Zambretti (current):', zambretti(params, hourly_data[idx]))
        idx = timezone.to_local(idx)
        if idx.hour < 8 or (idx.hour == 8 and idx.minute < 30):
            idx -= timedelta(hours=24)
        idx = idx.replace(hour=9, minute=0, second=0)
        idx = timezone.to_naive(idx)
        idx = hourly_data.nearest(idx)
        lcl = timezone.to_local(idx)
        print('Zambretti (at %s):' % lcl.strftime('%H:%M %Z'), zambretti(
            params, hourly_data[idx]))
    return 0
github jim-easterbrook / pywws / src / pywws / reprocess.py View on Github external
def reprocess(data_dir, update):
    with pywws.storage.pywws_context(data_dir) as context:
        if update:
            logger.warning("Updating status to detect invalid wind_dir")
            count = 0
            raw_data = context.raw_data
            for data in raw_data[:]:
                count += 1
                idx = data['idx']
                if count % 10000 == 0:
                    logger.info("update: %s", idx.isoformat(' '))
                elif count % 500 == 0:
                    logger.debug("update: %s", idx.isoformat(' '))
                if data['wind_dir'] is not None and (data['wind_dir'] & 0x80):
                    data['wind_dir'] = None
                    raw_data[idx] = data
            raw_data.flush()
        # delete old format summary files
github jim-easterbrook / pywws / src / pywws / template.py View on Github external
except getopt.error as msg:
        print('Error: %s\n' % msg, file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 1
    # check arguments
    if len(args) != 3:
        print('Error: 3 arguments required\n', file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 2
    # process options
    for o, a in opts:
        if o == '--help':
            print(__usage__.strip())
            return 0
    pywws.logger.setup_handler(1)
    with pywws.storage.pywws_context(args[0]) as context:
        pywws.localisation.set_application_language(context.params)
        return Template(context).make_file(args[1], args[2])
github jim-easterbrook / pywws / src / pywws / toservice.py View on Github external
verbose = 0
    for o, a in opts:
        if o == '-h' or o == '--help':
            print(__usage__.strip())
            return 0
        elif o == '-c' or o == '--catchup':
            catchup = True
        elif o == '-v' or o == '--verbose':
            verbose += 1
    # check arguments
    if len(args) != 2:
        print("Error: 2 arguments required", file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 2
    pywws.logger.setup_handler(verbose)
    with pywws.storage.pywws_context(args[0]) as context:
        return ToService(context, args[1]).Upload(
            catchup=catchup, ignore_last_update=not catchup)
github jim-easterbrook / pywws / src / pywws / process.py View on Github external
# process options
    verbose = 0
    for o, a in opts:
        if o in ('-h', '--help'):
            print(__usage__.strip())
            return 0
        elif o in ('-v', '--verbose'):
            verbose += 1
    # check arguments
    if len(args) != 1:
        print('Error: 1 argument required\n', file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 2
    pywws.logger.setup_handler(verbose)
    data_dir = args[0]
    with pywws.storage.pywws_context(data_dir) as context:
        return process_data(context)
github jim-easterbrook / pywws / src / pywws / plot.py View on Github external
except getopt.error as msg:
        print('Error: %s\n' % msg, file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 1
    # process options
    for o, a in opts:
        if o == '-h' or o == '--help':
            print(__usage__.strip())
            return 0
    # check arguments
    if len(args) != 4:
        print('Error: 4 arguments required\n', file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 2
    pywws.logger.setup_handler(2)
    with pywws.storage.pywws_context(args[0]) as context:
        pywws.localisation.set_application_language(context.params)
        return GraphPlotter(context, args[1]).do_plot(
            GraphFileReader(args[2]), args[3])