pywws.service.openweathermap

Upload weather data to Open Weather Map.

Open Weather Map is a Latvian based IT company seeking to provide affordable weather data.

Configuring pywws to use Open Weather Map is a bit more complicated than with other services. Start by running the module to set some default values in weather.ini (with no other pywws software running):

python -m pywws.service.openweathermap data_dir

After signing up and logging in to Open Weather Map visit the API keys page and copy your default key to the api key entry in weather.ini. The external id field is a single word name to identify your station. You could use a name based on your post code, or maybe your id from Weather Underground or CWOP. The station name is a longer, human readable, name. I’m not sure what use Open Weather Map makes of either of these. lat and long should be set to the latitude and longitude of your station (in degrees) and alt to its altitude in metres.

After setting (or changing) the above fields you need to “register” your station with Open Weather Map. This is done by running the module with the -r flag:

python -m pywws.service.openweathermap -r -v data_dir

If you already have any stations registered with Open Weather Map this will show you their details. You can select one of these existing stations or register a new one. pywws then sends the configuration values from weather.ini to Open Weather Map.

If this succeeds then Open Weather Map will have allocated a station id value which pywws stores in weather.ini. All this complication is to allow more than one station to be attached to one user’s account.

Classes

ToService(context[, check_params])
class pywws.service.openweathermap.ToService(context, check_params=True)[source]

Bases: pywws.service.CatchupDataService

config = {'alt': ('', False, None), 'api key': ('', True, None), 'external id': ('', False, None), 'lat': ('', False, None), 'long': ('', False, None), 'station id': ('', True, 'station_id'), 'station name': ('', False, None)}
logger = <Logger pywws.service.openweathermap (WARNING)>
service_name = 'openweathermap'
template = '\n#live#\n#idx "\'dt\' : %s,"#\n#temp_out "\'temperature\': %.1f,"#\n#wind_ave "\'wind_speed\' : %.1f,"#\n#wind_gust "\'wind_gust\' : %.1f,"#\n#wind_dir "\'wind_deg\' : %.0f," "" "winddir_degrees(x)"#\n#rel_pressure "\'pressure\' : %.1f,"#\n#hum_out "\'humidity\' : %.d,"#\n#calc "rain_hour(data)" "\'rain_1h\': %.1f,"#\n#calc "rain_24hr(data)" "\'rain_24h\': %.1f,"#\n#calc "dew_point(data[\'temp_out\'], data[\'hum_out\'])" "\'dew_point\': %.1f,"#\n'
session()[source]

Context manager factory function for a batch of one or more uploads.

This makes it easy to ensure any resources such as an internet connection are properly closed after a batch of uploads. Use the contextlib.contextmanager() decorator when you implement this method.

For a typical example, see the source code of the pywws.service.openweathermap module. If your upload can’t benefit from a session object yield None, as in pywws.service.copy.

upload_data(session, prepared_data={})[source]

Upload one data set to the service.

Every data service class must implement this method.

Parameters:
  • session (object) – the object created by session(). This is typically used to communicate with the server and is automatically closed when a batch of uploads has finished.
  • prepared_data (dict) – a set of key: value pairs to upload. The keys and values must all be text strings.
register()[source]

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