-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.py
41 lines (31 loc) · 1015 Bytes
/
login.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
from utils import login
import json
import requests
import os
try:
os.mkdir("settings")
os.mkdir("settings/devices")
except FileExistsError:
pass
client_id = 2882303761517308695
client_secret = "OrwZHJ/drEXakH1LsfwwqQ=="
data = login.get_token(client_id, client_secret)
settings = {"clientId": client_id, "accessToken": data["access_token"], "region": "de"}
with open("settings/settings.json", "w") as write_file:
json.dump(settings, write_file)
payload = {
"clientId": client_id,
"accessToken": data["access_token"],
}
url = "https://de.openapp.io.mi.com/openapp/user/device_list"
r = requests.post(
url,
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=payload,
)
list_id = []
devices_json = json.loads(r.text)
for x in devices_json["result"]["list"]:
lamps = {"did": x["did"], "name": x["name"], "model": x["model"], "mac": x["mac"]}
with open(f'settings/devices/{x["name"]}.json', "w") as write_file:
json.dump(lamps, write_file)