-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-heotemp.py
39 lines (30 loc) · 970 Bytes
/
2-heotemp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
import urllib
import urllib2
import json
import logging
token = 'HjXQxa5ItI' # Required
# logging
logging.basicConfig(filename='2-measure_env.log', format='%(asctime)s: %(levelname)s - %(message)s', level=logging.DEBUG)
def save_env_measure(humidity, temperature):
url = 'http://sw.hongphucjsc.com/api/weathers'
data = {
'humidity': humidity,
'temperature': temperature,
'wind_speed': 0,
'temp_mode': 1,
'wind_mode': 1,
'id_site': 1
}
header = {'hpswine_token': token}
req = urllib2.Request(url, urllib.urlencode(data), header)
try:
res = urllib2.urlopen(req)
if (res.getcode() == 200):
result = res.read()
result = json.loads(result)
if (result['status'] == 1):
print 'saved'
except Exception, e:
logging.error("Code: {0}, Reason: {1}".format(e.code, e.reason))
save_env_measure(60, 30)