Mercurial > ~darius > hgwebdir.cgi > agl
changeset 19:1d08f777533f default tip
Add installid parameter instead of hard coding it into a URL.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 03 Jul 2018 13:26:28 +0930 |
parents | 156ab071a9de |
children | |
files | agl.py |
diffstat | 1 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/agl.py Mon Sep 11 22:46:50 2017 +0930 +++ b/agl.py Tue Jul 03 13:26:28 2018 +0930 @@ -13,7 +13,7 @@ import tzlocal loginurl = 'https://command.aglsolar.com.au/api/v2/Account/LoginUser' -dataurl = 'https://command.aglsolar.com.au/api/v2/graph/b8e08afb-818f-4d2d-9d28-5afe8fc76a32' +dataurl = 'https://command.aglsolar.com.au/api/v2/graph/' # ?endDate=2017-08-23&granularity=Minute&metrics=read&startDate=2017-08-23&units=W' logouturl = 'https://command.aglsolar.com.au/api/v2/Account/Logout' @@ -66,6 +66,7 @@ dbh = sqlite3.connect(dbfn, detect_types = sqlite3.PARSE_DECLTYPES) cur = dbh.cursor() if args.update: + installid = conf.get('DEFAULT', 'installid') date = start while date < end: if conf.has_option('DEFAULT', 'token'): @@ -75,11 +76,11 @@ conf.set('DEFAULT', 'token', token) conf.write(file(confname, 'w')) - data = getdata(token, date, date) + data = getdata(token, installid, date, date) if data == None: #print('Getting new token') token = gettoken(username, password) - data = getdata(token, date, date) + data = getdata(token, installid, date, date) if data == None: print('Unable to fetch data') updatedb(cur, data) @@ -218,8 +219,10 @@ for idx in range(len(cols)): col = cols[idx] ydata = ary[:,idx + 1] + + ydata = [0 if v is None else v for v in ydata] if col in convs: - ydata = convs[col](ydata) + ydata = map(convs[col], ydata) if col in scale_limits: scale_min = scale_limits[col][0] scale_max = scale_limits[col][1] @@ -328,9 +331,9 @@ return None return json.decoder.JSONDecoder().decode(reply.content)['access_token'] -def getdata(token, startdate, enddate): +def getdata(token, installid, startdate, enddate): #print('getting ' + startdate.strftime('%Y-%m-%d')) - reply = requests.request('GET', dataurl, params = { + reply = requests.request('GET', dataurl + installid, params = { 'startDate' : startdate.strftime('%Y-%m-%d'), 'endDate' : enddate.strftime('%Y-%m-%d'), 'granularity' : 'Minute',