annotate py/uploader.py @ 248:317a1738f15c

Update to bottle 0.12.8
author Matt Johnston <matt@ucc.asn.au>
date Wed, 27 May 2015 22:17:39 +0800
parents 19569cb5ed46
children 86e638d564b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 import json
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 import hmac
233
19569cb5ed46 better arg parser. seems close to ready
Matt Johnston <matt@ucc.asn.au>
parents: 231
diff changeset
3 import hashlib
145
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 import zlib
160
256505f98c4d uploader works
Matt Johnston <matt@ucc.asn.au>
parents: 146
diff changeset
5 import binascii
215
4d82099d1fe0 use requests rather than urllib2, better ipv6->ipv4 fallback
Matt Johnston <matt@ucc.asn.au>
parents: 190
diff changeset
6 import logging
228
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
7 import asyncio
160
256505f98c4d uploader works
Matt Johnston <matt@ucc.asn.au>
parents: 146
diff changeset
8
228
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
9 import aiohttp
160
256505f98c4d uploader works
Matt Johnston <matt@ucc.asn.au>
parents: 146
diff changeset
10
256505f98c4d uploader works
Matt Johnston <matt@ucc.asn.au>
parents: 146
diff changeset
11 import config
256505f98c4d uploader works
Matt Johnston <matt@ucc.asn.au>
parents: 146
diff changeset
12 from utils import L,D,EX,W,E
256505f98c4d uploader works
Matt Johnston <matt@ucc.asn.au>
parents: 146
diff changeset
13 import utils
145
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14
228
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
15 class Uploader(object):
145
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 def __init__(self, server):
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 self.server = server
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18
228
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
19 @asyncio.coroutine
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
20 def run(self):
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
21 # wait for the first read
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
22 yield from asyncio.sleep(5)
145
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 while True:
228
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
24 yield from self.do()
d9e81a563923 porting to asyncio
Matt Johnston <matt@ucc.asn.au>
parents: 219
diff changeset
25 yield from self.server.sleep(config.UPLOAD_SLEEP)
145
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 def get_tosend(self, readings):
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 tosend = {}
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 tosend['fridge_on'] = self.server.fridge.is_on()
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 tosend['now'] = self.server.now()
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 tosend['readings'] = readings
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 tosend['wort_name'] = self.server.wort_name
160
256505f98c4d uploader works
Matt Johnston <matt@ucc.asn.au>
parents: 146
diff changeset
36 tosend['fridge_name'] = self.server.wort_name
145
6517ddee3187 few more bits
Matt Johnston <matt@ucc.asn.au>