Skip to content

Commit

Permalink
Removed service upload_data 'live' param
Browse files Browse the repository at this point in the history
This was only used by pywws.service.underground, and isn't a good way to
detect current data anyway.

Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Aug 30, 2018
1 parent ff164bd commit 6eb7960
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.8.0'
_release = '1618'
_commit = '2ac2f98'
_release = '1619'
_commit = 'ff164bd'
2 changes: 1 addition & 1 deletion src/pywws/examples/modules/aws_api_gw_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def session(self):
with requests.Session() as session:
yield session

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
try:
if self.params['http headers']:
for header in eval(self.params['http headers']):
Expand Down
23 changes: 10 additions & 13 deletions src/pywws/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def __init__(self, context, check_params=True):
else:
self.last_update = datetime.min

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
"""Upload one data set to the service.
Every data service class must implement this method.
Expand All @@ -270,21 +270,18 @@ def upload_data(self, session, prepared_data={}, live=False):
a batch of uplaods has finished.
:param dict prepared_data: a set of key: value pairs to upload.
The keys and values must all be text strings.
:param bool live: is this set of data "live" or "logged". This
is used by :py:mod:`pywws.service.underground` to select the
server to use.
"""
raise NotImplementedError()

def queue_data(self, timestamp, data, live):
def queue_data(self, timestamp, data):
if timestamp and timestamp < self.last_update + self.interval:
return False
if not self.valid_data(data):
return False
prepared_data = self.prepare_data(data)
prepared_data.update(self.fixed_data)
self.logger.debug('data: %s', str(prepared_data))
self.queue.append((timestamp, prepared_data, live))
self.queue.append((timestamp, prepared_data))
if timestamp:
self.last_update = timestamp
return True
Expand All @@ -309,9 +306,9 @@ def upload_batch(self):
if upload is None:
OK = False
break
timestamp, prepared_data, live = upload
timestamp, prepared_data = upload
OK, message = self.upload_data(
session, prepared_data=prepared_data, live=live)
session, prepared_data=prepared_data)
self.log(message)
if not OK:
break
Expand Down Expand Up @@ -342,12 +339,12 @@ def do_catchup(self, do_all=False):
self.context.shutdown.wait(4.0)
if self.context.shutdown.is_set():
return True
self.queue_data(data['idx'], data, False)
self.queue_data(data['idx'], data)
return True
for data in self.context.calib_data[start:]:
if self.queue.full():
return True
if self.queue_data(data['idx'], data, False):
if self.queue_data(data['idx'], data):
return False
return True

Expand All @@ -364,10 +361,10 @@ def upload(self, live_data=None, test_mode=False, options=()):
idx = self.context.calib_data.after(timestamp + SECOND)
if test_mode:
timestamp = None
if self.queue_data(timestamp, data, False):
if self.queue_data(timestamp, data):
break
if live_data and not idx:
self.queue_data(live_data['idx'], live_data, True)
self.queue_data(live_data['idx'], live_data)


class LiveDataService(DataServiceBase):
Expand All @@ -389,7 +386,7 @@ def upload(self, live_data=None, test_mode=False, options=()):
timestamp = data['idx']
if test_mode:
timestamp = None
self.queue_data(timestamp, data, bool(live_data))
self.queue_data(timestamp, data)

def upload_batch(self):
# remove stale uploads from queue
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/cwop.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def session(self):
logger.debug('server software: %s', response.strip())
yield session

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
login = ('user {designator:s} pass {passcode:s} ' +
'vers pywws {version:s}\n').format(**prepared_data)
logger.debug('login: "{:s}"'.format(login))
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/metoffice.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def valid_data(self, data):
'wind_dir', 'wind_ave', 'wind_gust', 'hum_out', 'temp_out',
'rel_pressure')])

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
try:
rsp = session.get('http://wow.metoffice.gov.uk/automaticreading',
params=prepared_data, timeout=60)
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def session(self):
finally:
session.disconnect()

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
logger.debug((
'publishing on topic "{topic:s}" with retain={retain!s},'
' data="{data!r}"').format(data=prepared_data, **self.params))
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/openweathermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def session(self):
session.params.update({'appid': self.params['api key']})
yield session

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
url = 'https://api.openweathermap.org/data/3.0/measurements'
try:
rsp = session.post(url, json=[prepared_data], timeout=60)
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/pwsweather.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def session(self):
with requests.Session() as session:
yield session

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
try:
rsp = session.get(
'http://www.pwsweather.com/pwsupdate/pwsupdate.php',
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/temperaturnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def session(self):
def valid_data(self, data):
return data['temp_out'] is not None

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
try:
rsp = session.get('http://www.temperatur.nu/rapportera.php',
params=prepared_data, timeout=60)
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/underground.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def prepare_data(self, data):
prepared_data['idx'] = data['idx']
return prepared_data

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
# extract timestamp from prepared_data
idx = prepared_data['idx']
del prepared_data['idx']
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/weathercloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def valid_data(self, data):
'429': 'too frequent data',
}

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
url = 'http://api.weathercloud.net/v01/set'
try:
rsp = session.get(url, params=prepared_data, timeout=60)
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/wetterarchivde.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def session(self):
with requests.Session() as session:
yield session

def upload_data(self, session, prepared_data={}, live=False):
def upload_data(self, session, prepared_data={}):
try:
rsp = session.post('http://interface.wetterarchiv.de/weather/',
data=prepared_data, timeout=60)
Expand Down

0 comments on commit 6eb7960

Please sign in to comment.