### Navigation

- index
- modules |
- next |
- previous |
- pywws 14.06.dev1238 documentation »
- Python programs and modules »

# pywws.toservice

Post weather update to services such as Weather Underground

    usage: python -m pywws.toservice [options] data_dir service_name
    options are:
     -h or --help     display this help
     -c or --catchup  upload all data since last upload
     -v or --verbose  increase amount of reassuring messages
    data_dir is the root directory of the weather data
    service_name is the service to upload to, e.g. underground

## Introduction

There are an increasing number of web sites around the world that encourage amateur weather station owners to upload data over the internet.

This module enables pywws to upload readings to these organisations. It is highly customisable using configuration files. Each ‘service’ requires a configuration file and one or two templates in `pywws/services` (that should not need to be edited by the user) and a section in `weather.ini` containing user specific data such as your site ID and password.

See How to integrate pywws with various weather services for details of the available services.

## Configuration

If you haven’t already done so, visit the organisation’s web site and create an account for your weather station. Make a note of any site ID and password details you are given.

Stop any pywws software that is running and then run `toservice` to create a section in `weather.ini`:

    python -m pywws.toservice data_dir service_name

`service_name` is the single word service name used by pywws, such as `metoffice`, `data_dir` is your weather data directory, as usual.

Edit `weather.ini` and find the section corresponding to the service name, e.g. `[underground]`. Copy your site details into this section, for example:

    [underground]
    password = secret
    station = ABCDEFG1A

Now you can test your configuration:

    python -m pywws.toservice -vvv data_dir service_name

This should show you the data string that is uploaded. Any failure should generate an error message.

## Upload old data

Now you can upload your last 7 days’ data, if the service supports it. Run `toservice` with the catchup option:

    python -m pywws.toservice -cvv data_dir service_name

This may take 20 minutes or more, depending on how much data you have.

## Add service(s) upload to regular tasks

Edit your `weather.ini` again, and add a list of services to the `[live]`, `[logged]`, `[hourly]`, `[12 hourly]` or `[daily]` section, depending on how often you want to send data. For example:

    [live]
    twitter = []
    plot = []
    text = []
    services = ['underground_rf', 'cwop']

    [logged]
    twitter = []
    plot = []
    text = []
    services = ['metoffice', 'cwop']

    [hourly]
    twitter = []
    plot = []
    text = []
    services = ['underground']

Note that the `[live]` section is only used when running `pywws.LiveLog`. It is a good idea to repeat any service selected in `[live]` in the `[logged]` or `[hourly]` section in case you switch to running `pywws.Hourly`.

Restart your regular pywws program (`pywws.Hourly` or `pywws.LiveLog`) and visit the appropriate web site to see regular updates from your weather station.

## API

Functions

`ApplicationLogger`(verbose[, logfile]) |
`main`([argv]) |

Classes

`SafeConfigParser`([defaults, dict_type, ...]) |
`ToService`(params, status, calib_data, ...) | Upload weather data to weather services such as Weather Underground.
`datetime` | datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
`timedelta` | Difference between two datetime values.

class `pywws.toservice.``ToService`(params, status, calib_data, service_name)

  Upload weather data to weather services such as Weather Underground.

  Parameters: | params (`pywws.DataStore.params`) – pywws configuration. status (`pywws.DataStore.status`) – pywws status store. calib_data (`pywws.DataStore.calib_store`) – ‘calibrated’ data. service_name (string) – name of service to upload to.

  `prepare_data`(data)

    Prepare a weather data record.

    The `data` parameter contains the data to be encoded. It should be a ‘calibrated’ data record, as stored in `pywws.DataStore.calib_store`. The relevant data items are extracted and converted to strings using a template, then merged with the station’s “fixed” data.

    Parameters: | data (dict) – the weather data record.
    Returns: | dict.
    Return type: | string

  `aprs_send_data`(timestamp, prepared_data, ignore_last_update=False)

    Upload a weather data record using APRS.

    The `prepared_data` parameter contains the data to be uploaded. It should be a dictionary of string keys and string values.

    Parameters: | timestamp (datetime) – the timestamp of the data to upload. prepared_data (dict) – the data to upload. ignore_last_update (bool) – don’t get or set the ‘last update’ status.ini entry.
    Returns: | success status
    Return type: | bool

  `http_send_data`(timestamp, prepared_data, ignore_last_update=False)

    Upload a weather data record using HTTP.

    The `prepared_data` parameter contains the data to be uploaded. It should be a dictionary of string keys and string values.

    Parameters: | timestamp (datetime) – the timestamp of the data to upload. prepared_data (dict) – the data to upload. ignore_last_update (bool) – don’t get or set the ‘last update’ status.ini entry.
    Returns: | success status
    Return type: | bool

  `next_data`(catchup, live_data, ignore_last_update=False)

    Get weather data records to upload.

    This method returns either the most recent weather data record, or all records since the last upload, according to the value of `catchup`.

    Parameters: | catchup (boolean) – `True` to get all records since last upload, or `False` to get most recent data only. live_data (dict) – a current ‘live’ data record, or `None`. ignore_last_update (bool) – don’t get the ‘last update’ status.ini entry.
    Returns: | yields weather data records.
    Return type: | dict

  `set_last_update`(timestamp)
  `Upload`(catchup=True, live_data=None, ignore_last_update=False)

    Upload one or more weather data records.

    This method uploads either the most recent weather data record, or all records since the last upload (up to 7 days), according to the value of `catchup`.

    It sets the `last update` configuration value to the time stamp of the most recent record successfully uploaded.

    Parameters: | catchup (bool) – upload all data since last upload. live_data (dict) – current ‘live’ data. If not present the most recent logged data is uploaded. ignore_last_update (bool) – don’t get or set the ‘last update’ status.ini entry.
    Returns: | success status
    Return type: | bool

`pywws.toservice.``main`(argv=None)

Comments or questions? Please subscribe to the pywws mailing list http://groups.google.com/group/pywws and let us know.

### Navigation

- index
- modules |
- next |
- previous |
- pywws 14.06.dev1238 documentation »
- Python programs and modules »