kopia lustrzana https://codeberg.org/argrento/huami-token
App version bump, api change, show active status of a device
rodzic
c1206af390
commit
3e79d9ab33
|
@ -19,7 +19,6 @@ from rich import box
|
||||||
|
|
||||||
import urls
|
import urls
|
||||||
|
|
||||||
|
|
||||||
class HuamiAmazfit:
|
class HuamiAmazfit:
|
||||||
"""Base class for logging in and receiving auth keys and GPS packs"""
|
"""Base class for logging in and receiving auth keys and GPS packs"""
|
||||||
def __init__(self, method="amazfit", email=None, password=None):
|
def __init__(self, method="amazfit", email=None, password=None):
|
||||||
|
@ -133,7 +132,7 @@ class HuamiAmazfit:
|
||||||
self.user_id = token_info['user_id']
|
self.user_id = token_info['user_id']
|
||||||
print("Logged in! User id: {}".format(self.user_id))
|
print("Logged in! User id: {}".format(self.user_id))
|
||||||
|
|
||||||
def get_wearable_auth_keys(self) -> dict:
|
def get_wearables(self) -> dict:
|
||||||
"""Request a list of linked devices"""
|
"""Request a list of linked devices"""
|
||||||
print("Getting linked wearables...")
|
print("Getting linked wearables...")
|
||||||
|
|
||||||
|
@ -141,15 +140,16 @@ class HuamiAmazfit:
|
||||||
|
|
||||||
headers = urls.PAYLOADS['devices']
|
headers = urls.PAYLOADS['devices']
|
||||||
headers['apptoken'] = self.app_token
|
headers['apptoken'] = self.app_token
|
||||||
|
params = {'enableMultiDevice': 'true'}
|
||||||
|
|
||||||
response = requests.get(devices_url, headers=headers)
|
response = requests.get(devices_url, params=params, headers=headers)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
device_request = response.json()
|
device_request = response.json()
|
||||||
if 'items' not in device_request:
|
if 'items' not in device_request:
|
||||||
raise ValueError("No 'items' parameter in devices data.")
|
raise ValueError("No 'items' parameter in devices data.")
|
||||||
devices = device_request['items']
|
devices = device_request['items']
|
||||||
|
|
||||||
devices_dict = {}
|
wearables = []
|
||||||
|
|
||||||
for wearable in devices:
|
for wearable in devices:
|
||||||
if 'macAddress' not in wearable:
|
if 'macAddress' not in wearable:
|
||||||
|
@ -165,9 +165,15 @@ class HuamiAmazfit:
|
||||||
key_str = device_info['auth_key']
|
key_str = device_info['auth_key']
|
||||||
auth_key = '0x' + (key_str if key_str != '' else '00')
|
auth_key = '0x' + (key_str if key_str != '' else '00')
|
||||||
|
|
||||||
devices_dict[f'{mac_address}'] = auth_key
|
wearables.append(
|
||||||
|
{
|
||||||
|
'active_status': str(wearable['activeStatus']) if 'activeStatus' in wearable else '-1',
|
||||||
|
'mac_address': mac_address,
|
||||||
|
'auth_key': auth_key
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return devices_dict
|
return wearables
|
||||||
|
|
||||||
def get_gps_data(self) -> None:
|
def get_gps_data(self) -> None:
|
||||||
"""Download GPS packs: almanac and AGPS"""
|
"""Download GPS packs: almanac and AGPS"""
|
||||||
|
@ -252,6 +258,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
table = Table(show_header=True, header_style="bold", box=box.ASCII)
|
table = Table(show_header=True, header_style="bold", box=box.ASCII)
|
||||||
|
table.add_column("ACT", width=3, justify='center')
|
||||||
table.add_column("MAC", style="dim", width=17, justify='center')
|
table.add_column("MAC", style="dim", width=17, justify='center')
|
||||||
table.add_column("auth_key", width=50, justify='center')
|
table.add_column("auth_key", width=50, justify='center')
|
||||||
|
|
||||||
|
@ -265,9 +272,9 @@ if __name__ == "__main__":
|
||||||
device.login()
|
device.login()
|
||||||
|
|
||||||
if args.bt_keys or args.all:
|
if args.bt_keys or args.all:
|
||||||
device_keys = device.get_wearable_auth_keys()
|
wearables = device.get_wearables()
|
||||||
for device_key in device_keys:
|
for wearable in wearables:
|
||||||
table.add_row(device_key, device_keys[device_key])
|
table.add_row(wearable['active_status'], wearable['mac_address'], wearable['auth_key'])
|
||||||
console.print(table)
|
console.print(table)
|
||||||
|
|
||||||
if args.gps or args.all:
|
if args.gps or args.all:
|
||||||
|
|
7
urls.py
7
urls.py
|
@ -10,7 +10,7 @@ URLS = {
|
||||||
'devices': 'https://api-mifit-us2.huami.com/users/{user_id}/devices',
|
'devices': 'https://api-mifit-us2.huami.com/users/{user_id}/devices',
|
||||||
'agps': 'https://api-mifit-us2.huami.com/apps/com.huami.midong/fileTypes/{pack_name}/files',
|
'agps': 'https://api-mifit-us2.huami.com/apps/com.huami.midong/fileTypes/{pack_name}/files',
|
||||||
'data_short': 'https://api-mifit-us2.huami.com/users/{user_id}/deviceTypes/4/data',
|
'data_short': 'https://api-mifit-us2.huami.com/users/{user_id}/deviceTypes/4/data',
|
||||||
'logout': 'https://account-us2.huami.com/v1/client/logout'
|
'logout': 'https://account-us2.huami.com/v1/client/logout',
|
||||||
}
|
}
|
||||||
|
|
||||||
PAYLOADS = {
|
PAYLOADS = {
|
||||||
|
@ -28,7 +28,7 @@ PAYLOADS = {
|
||||||
'dn': 'account.huami.com,api-user.huami.com,app-analytics.huami.com,'
|
'dn': 'account.huami.com,api-user.huami.com,app-analytics.huami.com,'
|
||||||
'api-watch.huami.com,'
|
'api-watch.huami.com,'
|
||||||
'api-analytics.huami.com,api-mifit.huami.com',
|
'api-analytics.huami.com,api-mifit.huami.com',
|
||||||
'app_version': '4.3.0-play',
|
'app_version': '5.9.2-play_100355',
|
||||||
'source': 'com.huami.watch.hmwatchmanager',
|
'source': 'com.huami.watch.hmwatchmanager',
|
||||||
'country_code': None,
|
'country_code': None,
|
||||||
'device_id': None,
|
'device_id': None,
|
||||||
|
@ -41,7 +41,8 @@ PAYLOADS = {
|
||||||
'grant_type': None
|
'grant_type': None
|
||||||
},
|
},
|
||||||
'devices': {
|
'devices': {
|
||||||
'apptoken': None
|
'apptoken': None,
|
||||||
|
# 'enableMultiDevice': 'true'
|
||||||
},
|
},
|
||||||
'agps': {
|
'agps': {
|
||||||
'apptoken': None
|
'apptoken': None
|
||||||
|
|
Ładowanie…
Reference in New Issue