How to use the pywws.logger 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 / 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 / hourly.py View on Github external
return 1
    # process options
    verbose = 0
    for o, a in opts:
        if o == '-h' or o == '--help':
            print(__doc__.split('\n\n')[0])
            print(usage)
            return 0
        elif o == '-v' or o == '--verbose':
            verbose += 1
    # check arguments
    if len(args) != 1:
        print('Error: 1 argument required\n', file=sys.stderr)
        print(usage, file=sys.stderr)
        return 2
    pywws.logger.setup_handler(verbose)
    return hourly(args[0])
github jim-easterbrook / pywws / src / pywws / setweatherstation.py View on Github external
elif o in ('-d', '--default'):
            default = True
        elif o in ('-p', '--pressure'):
            pressure = int((float(a) * 10.0) + 0.5)
        elif o in ('-r', '--read_period'):
            read_period = int(a)
        elif o in ('-v', '--verbose'):
            verbose += 1
        elif o in ('-z', '--zero_memory'):
            zero_memory = True
    # check arguments
    if len(args) != 0:
        print("Error: No arguments required", file=sys.stderr)
        print(__usage__.strip(), file=sys.stderr)
        return 2
    pywws.logger.setup_handler(verbose)
    # open connection to weather station
    ws = pywws.weatherstation.WeatherStation()
    # set data to be sent to station
    data = []
    # set default values
    if default:
        ptr = ws.fixed_format['settings_1'][0]
        data.append((ptr, 0b00100000))
        ptr = ws.fixed_format['settings_2'][0]
        data.append((ptr, 0b00001000))
        ptr = ws.fixed_format['display_1'][0]
        data.append((ptr, 0b01000001))
        ptr = ws.fixed_format['display_2'][0]
        data.append((ptr, 0b00001001))
        ptr = ws.fixed_format['alarm_1'][0]
        data.append((ptr, 0b00000000))
github jim-easterbrook / pywws / src / pywws / windrose.py View on Github external
opts, args = getopt.getopt(argv[1:], "h", ['help'])
    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 RosePlotter(context, args[1]).do_plot(args[2], args[3])
github jim-easterbrook / pywws / src / pywws / logdata.py View on Github external
for o, a in opts:
        if o in ('-h', '--help'):
            print(__usage__.strip())
            return 0
        elif o in ('-c', '--clear'):
            clear = True
        elif o in ('-s', '--sync'):
            sync = int(a)
        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)
    root_dir = args[0]
    with pywws.storage.pywws_context(root_dir) as context:
        DataLogger(context).log_data(sync=sync, clear=clear)
github jim-easterbrook / pywws / src / pywws / plot.py View on Github external
opts, args = getopt.getopt(argv[1:], "h", ['help'])
    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])
github jim-easterbrook / pywws / src / pywws / template.py View on Github external
opts, args = getopt.getopt(argv[1:], "", ['help'])
    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 / datastoretransfer.py View on Github external
files by hand is likely to be faster.

Config files such as weather.ini, and folders such as templates etc.
are not copied, so please ensure you consider seperately if required.
"""

from __future__ import absolute_import, print_function

import argparse
import importlib
import logging

import pywws.logger

logger = logging.getLogger(__name__)
pywws.logger.setup_handler(1)

def monitor(i):
    """Given an iterator, yields data from it
    but prints progress every 10,000 records"""
    count = 0
    for x in i:
        count+=1
        if count % 10000 == 0:
            logger.info("%d records so far, current record is %s",
                count, x["idx"])
        yield x

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="""Copy pywws data from one storage system to another.
        You must specify the pywws data module, and the path for both
github jim-easterbrook / pywws / src / pywws / toservice.py View on Github external
catchup = False
    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)