Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add PWS publisher class; fixes #1

  • Loading branch information...
commit c1879c3c795d0b88420c704f0ccb128d3f241118 1 parent e6d2927
@cmcginty authored
View
5 scripts/weatherpub.py
@@ -32,7 +32,8 @@
# key expected to match optparse destination paramter
# value defines class object of publication service
PUB_SERVICES = {
- 'wug' : weather.services.Wunderground
+ 'wug' : weather.services.Wunderground,
+ 'pws' : weather.services.PWS,
}
@@ -147,6 +148,8 @@ def get_options(parser):
of weather data.''', )
pub_g.add_option('-w', '--wundergound', nargs=2, type='string', dest='wug',
help='Weather Underground service; WUG=[SID(station ID), PASSWORD]')
+ pub_g.add_option('-p', '--pws', nargs=2, type='string', dest='pws',
+ help='PWS service; PWS=[SID(station ID), PASSWORD]')
parser.add_option_group(pub_g)
parser.add_option('-d', '--debug', dest='debug', action="store_true",
View
1  weather/services/__init__.py
@@ -1 +1,2 @@
from wunderground import *
+from pws import *
View
9 weather/services/_base.py
@@ -15,10 +15,10 @@ class HttpPublisher(object):
'''
Abstract base class for creation generic HTTP publication services
'''
-
- STD_SERVER = None
- REALTIME_SERVER = None
- URI = None
+ SOFTWARE = 'PyWeather'
+ STD_SERVER = None
+ REALTIME_SERVER = None
+ URI = None
def __init__(self, sid, password, rtfreq=None):
self.sid = sid
@@ -40,6 +40,7 @@ def _publish(args, server, uri):
from httplib import HTTPConnection
from urllib import urlencode
+ args = dict((k,v) for k,v in args.items() if v != 'NA')
uri = uri + "?" + urlencode(args)
log.debug('Connect to: http://%s' % server)
View
87 weather/services/pws.py
@@ -0,0 +1,87 @@
+'''
+PWSweather.com Publisher
+WeatherForYou.com Publisher
+
+Abstract:
+The class contained within this module allows python programs to
+publish weather conditions to the pwsweather.com servers.
+
+Usage:
+>>> publisher = PWS( 'MySiteID', 'MyPassowrd')
+>>> publisher.set( ... )
+>>> response = publisher.publish()
+>>> print '%s: %s' % (response.status, response.reason)
+
+Notes on arguments to Publisher.set():
+<float> pressure: in inches of Hg
+<float> dewpoint: in Fahrenheit
+<float> humidity: between 0.0 and 100.0 inclusive
+<float> tempf: in Fahrenheit
+<float> rainin: inches/hour of rain
+<float> rainday: total rainfall for day (localtime)
+<float> rainmonth: total rainfall for month (localtime)
+<float> rainyear: total rainfall for year (localtime)
+<tuple> dateutc: 9 value time tuple in UTC (e.g. time.gmtime())
+<float> windgust: in mph
+<float> windspeed: in mph
+<float> winddir: in degrees, between 0.0 and 360.0
+<string> weather: unknown at this time (email me if you know!)
+
+Author: Patrick C. McGinty (pyweather@tuxcoder.com)
+Date: Tuesday, July 13 2010
+'''
+
+from __future__ import absolute_import
+
+import logging
+log = logging.getLogger(__name__)
+
+from . _base import *
+
+
+class PWS(HttpPublisher):
+ '''
+ Publishes weather data to the pwsweather.com servers. See module
+ documentation for additional information and usage idioms.
+ '''
+ STD_SERVER = "www.pwsweather.com"
+ URI = "/pwsupdate/pwsupdate.php"
+
+ def __init__(self, sid, password):
+ super(PWS,self).__init__(sid,password)
+ self.args = { 'ID':sid,
+ 'PASSWORD':password,
+ 'action':'updateraw',
+ 'softwaretype':self.SOFTWARE, }
+ self.server = self.STD_SERVER
+
+
+ def set( self, pressure='NA', dewpoint='NA', humidity='NA', tempf='NA',
+ rainin='NA', rainday='NA', rainmonth='NA', rainyear='NA',
+ dateutc='NA', windgust='NA', windspeed='NA', winddir='NA',
+ weather='NA', *args, **kw):
+ '''
+ Usefull for defining weather data published to the server. Parameters not
+ sent will be cleared and not set to server. Unknown keyword args will be
+ silently ignored, so be careful. This is necessory for publishers that
+ support more fields than others.
+ '''
+ # unused, but valid, parameters are:
+ # solarradiation, UV
+ self.args.update( {
+ 'baromin':pressure,
+ 'dailyrainin':rainday,
+ 'dateutc':dateutc,
+ 'dewptf':dewpoint,
+ 'humidity':humidity,
+ 'monthrainin':rainmonth,
+ 'rainin':rainin,
+ 'tempf':tempf,
+ 'weather':weather,
+ 'winddir':winddir,
+ 'windgustmph':windgust,
+ 'windspeedmph':windspeed,
+ 'yearrainin':rainyear,
+ } )
+ log.debug( self.args )
+
View
66 weather/services/wunderground.py
@@ -21,15 +21,19 @@
>>> print '%s: %s' % (response.status, response.reason)
Notes on arguments to Publisher.set():
-<float> pressure: in inches of Hg
-<float> dewpt: in Fahrenheit
-<float> humidity: between 0.0 and 100.0 inclusive
-<float> tempf: in Fahrenheit
-<time tuple> dateutc: 9 value time tuple in UTC (e.g. time.gmtime())
-<float> windgust: in mph
-<float> winddir: in degrees, between 0.0 and 100.0
-<string> clouds: unknown at this time (email me if you know!)
-<string> weather: unknown at this time (email me if you know!)
+<float> pressure: in inches of Hg
+<float> dewpoint: in Fahrenheit
+<float> humidity: between 0.0 and 100.0 inclusive
+<float> tempf: in Fahrenheit
+<float> rainin: inches/hour of rain
+<float> rainday: total rainfall in day (localtime)
+<tuple> dateutc: 9 value time tuple in UTC (e.g. time.gmtime())
+<float> windgust: in mph
+<float> windgustdir:in degrees, between 0.0 and 360.0
+<float> windspeed: in mph
+<float> winddir: in degrees, between 0.0 and 360.0
+<string> clouds: unknown at this time (email me if you know!)
+<string> weather: unknown at this time (email me if you know!)
Developers Notes:
It appears that even if you provide an invalid username and password,
@@ -54,7 +58,6 @@ class Wunderground(HttpPublisher):
Publishes weather data to the wunderground.com servers. See
module documentation for additional information and usage idioms.
'''
-
STD_SERVER = "weatherstation.wunderground.com"
REALTIME_SERVER = "rtupdate.wunderground.com"
URI = "/weatherstation/updateweatherstation.php"
@@ -64,7 +67,7 @@ def __init__(self, sid, password, rtfreq=None):
self.args = { 'ID':sid,
'PASSWORD':password,
'action':'updateraw',
- 'softwaretype':'PyWeather', }
+ 'softwaretype':self.SOFTWARE, }
if rtfreq:
self.args['realtime'] = 1
self.args['rtfreq'] = self.rtfreq
@@ -79,28 +82,33 @@ def set( self, pressure='NA', dewpoint='NA', humidity='NA', tempf='NA',
clouds='NA', weather='NA', *args, **kw):
'''
Usefull for defining weather data published to the server. Parameters
- not set will be cleared and not set to server. Unknown keyword args
- will be silently ignored, so be careful. This is necessory for
- publishers that support more fields than others.
+ not set will be reset and not sent to server. Unknown keyword args will
+ be silently ignored, so be careful. This is necessory for publishers
+ that support more fields than others.
'''
- self.args['baromin'] = pressure
- self.args['dewptf'] = dewpoint
- self.args['humidity'] = humidity
- self.args['tempf'] = tempf
- self.args['rainin'] = rainin
- self.args['dailyrainin'] = rainday
- self.args['dateutc'] = dateutc
- self.args['windgustmph'] = windgust
- self.args['windgustdir'] = windgustdir
- self.args['windspeedmph'] = windspeed
- self.args['winddir'] = winddir
- self.args['clouds'] = clouds
- self.args['weather'] = weather
- self.args = dict((k,v) for k,v in self.args.items() if v != 'NA')
+ # see: http://wiki.wunderground.com/index.php/PWS_-_Upload_Protocol
+ # unused, but valid, parameters are:
+ # windspdmph_avg2m, winddir_avg2m, windgustmph_10m, windgusdir_10m
+ # soiltempf, soilmoisture, leafwetness, solarradiation, UV
+ # indoortempf, indoorhumidity
+ self.args.update( {
+ 'baromin':pressure,
+ 'clouds':clouds,
+ 'dailyrainin':rainday,
+ 'dateutc':dateutc,
+ 'dewptf':dewpoint,
+ 'humidity':humidity,
+ 'rainin':rainin,
+ 'tempf':tempf,
+ 'weather':weather,
+ 'winddir':winddir,
+ 'windgustdir':windgustdir,
+ 'windgustmph':windgust,
+ 'windspeedmph':windspeed,
+ } )
log.debug( self.args )
-
# for legacy support <= v0.8.2, depreciated, do not use
Publisher = Wunderground
Please sign in to comment.
Something went wrong with that request. Please try again.