This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
awair.py
73 lines (57 loc) · 2.7 KB
/
awair.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import requests
import json
class awair:
def __init__(self, username, password, access_token=None):
self.username = username
self.password = password
if not access_token:
self.login()
else:
self.access_token = access_token
self.password = None
def make_request(self, url, params=None, method='GET'):
headers = { "Authorization":"Bearer " + self.access_token}
if params:
params = urllib.urlencode(params, True).replace('+', '%20')
if method == 'GET':
r = requests.get(url, params=params, headers=headers)
elif method == 'POST':
r = requests.post(url, params=params, headers=headers)
response = r.json()
return response
def login(self):
print("logging in")
url = "https://mobile-app.awair.is/v1/users/login"
data = {"email":self.username,"password":self.password}
#headers = {"Authorization":"Bearer MYREALLYLONGTOKENIGOT"}
response = requests.post(url,json=data).json()
self.access_token = response['accessToken']
self.user_id = response['userId']
def devices(self):
url = "https://internal.awair.is/v1.1/users/self/devices"
devices = self.make_request(url, method="GET")['data']
return devices
def inbox(self, lang="en",limit="20"):
url = "https://internal.awair.is/v1/users/self/inbox-items?lang=" + lang + "&limit=" + limit
inbox = self.make_request(url, method="GET")['data']
return inbox
def weather(self, latitude, longitude):
url = "https://internal.awair.is/v1.2/weather?latitude=" + str(latitude) + "&longitude=" + str(longitude)
weather = self.make_request(url, method="GET")
return weather
def contents(self, latitude, longitude):
url = "https://contents.awair.is/v1/contents?co2_index=0&dust_index=0&humid_index=2&humid_meta=low&lang=en&load_more=0&preference=General&score=87&score_color=green&temp_index=0&temp_meta=high&voc_index=0"
contents = self.make_request(url, method="GET")
return contents
def events_score(self, device_id, desc="true", limit="1"):
url = "https://internal.awair.is/v1/devices/awair/"+str(device_id)+"/events/score?desc="+desc+"&limit="+ limit
events = self.make_request(url, method="GET")
return events
def timeline(self, device_id, from_timestamp, to_timestamp):
url = "https://internal.awair.is/v1.2/devices/awair/"+str(device_id)+"/timeline?from="+from_timestamp+"&to="+to_timestamp
timeline = self.make_request(url, method="GET")
return timeline
def sleep_report(self, device_id, timestamp, lang="en" ):
url = "https://internal.awair.is/v1.2/users/self/devices/awair/"+str(device_id)+"/sleep-report?lang="+lang+"×tamp="+timestamp
timeline = self.make_request(url, method="GET")
return timeline