How to use the pywws.localisation 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 / forecast.py View on Github external
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 / plot.py View on Github external
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 / 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)
                    # do tasks
                    tasks.do_tasks()
github jim-easterbrook / pywws / src / pywws / windrose.py View on Github external
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 / forecast.py View on Github external
def zambretti(params, hourly_data):
    code = zambretti_code(params, hourly_data)
    return pywws.localisation.translation.ugettext(_forecast_text[code])
github jim-easterbrook / pywws / src / pywws / conversions.py View on Github external
def winddir_text(pts):
    "Convert wind direction from 0..15 to compass point text"
    global _winddir_text_array
    if pts is None:
        return None
    if not isinstance(pts, int):
        pts = int(pts + 0.5) % 16
    if not _winddir_text_array:
        _ = pywws.localisation.translation.ugettext
        _winddir_text_array = (
            _(u'N'), _(u'NNE'), _(u'NE'), _(u'ENE'),
            _(u'E'), _(u'ESE'), _(u'SE'), _(u'SSE'),
            _(u'S'), _(u'SSW'), _(u'SW'), _(u'WSW'),
            _(u'W'), _(u'WNW'), _(u'NW'), _(u'NNW'),
            )
    return _winddir_text_array[pts]
github jim-easterbrook / pywws / src / pywws / conversions.py View on Github external
def pressure_trend_text(trend):
    """Convert pressure trend to a string, as used by the UK met
    office.

    """
    _ = pywws.localisation.translation.ugettext
    if trend > 6.0:
        return _(u'rising very rapidly')
    elif trend > 3.5:
        return _(u'rising quickly')
    elif trend > 1.5:
        return _(u'rising')
    elif trend >= 0.1:
        return _(u'rising slowly')
    elif trend < -6.0:
        return _(u'falling very rapidly')
    elif trend < -3.5:
        return _(u'falling quickly')
    elif trend < -1.5:
        return _(u'falling')
    elif trend <= -0.1:
        return _(u'falling slowly')