diff --git a/README.md b/README.md index 1973a4c..a1a8f21 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,13 @@ Token: ['UaFHW53RJVYwqXaa7ncPQ'] Logging in... Logged in! User id: 1234567890 Getting linked wearables... - -Device 1. Mac = AB:CD:EF:12:34:56, auth_key = 0xa3c10e34e5c14637eea6b9efc061069 +┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ MAC ┃ auth_key ┃ +┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ AB:CD:EF:12:34:56 │ 0xa3c10e34e5c14637eea6b9efc06106 │ +└───────────────────┴──────────────────────────────────────┘ +Downloading AGPS_ALM... +Downloading AGPSZIP... Logged out. ``` @@ -64,9 +69,14 @@ Token: ['ALSG_CLOUDSRV_9B8D87D0EB77C71B45FF73B2266D922B'] Logging in... Logged in! User id: 3000654321 Getting linked wearables... - -Device 1. Mac = 12:34:56:AB:CD:EF, auth_key = 0x3c10e34e5c1463527579996fa83e6d -Device 2. Mac = BA:DC:FE:21:43:65, auth_key = 0x0 +┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ MAC ┃ auth_key ┃ +┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ +│ 12:34:56:AB:CD:EF │ 0x3c10e34e5c1463527579996fa83e6d │ +│ BA:DC:FE:21:43:65 │ 0x00 │ +└───────────────────┴──────────────────────────────────────┘ +Downloading AGPS_ALM... +Downloading AGPSZIP... Logged out. ``` @@ -87,6 +97,7 @@ the second one is my Xiaomi Mi Smart Scale._ * uuid * json * shutil +* rich ## Versioning @@ -95,5 +106,3 @@ We use [SemVer](http://semver.org/) for versioning. For the versions available, ## License This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details - - diff --git a/huami_token.py b/huami_token.py index 715515d..a19bc12 100644 --- a/huami_token.py +++ b/huami_token.py @@ -8,6 +8,9 @@ import urllib import argparse import requests +from rich.console import Console +from rich.table import Column, Table + import urls @@ -120,7 +123,7 @@ class HuamiAmazfit: print("Logged in! User id: {}".format(self.user_id)) def get_wearable_auth_keys(self): - print("Getting linked wearables...\n") + print("Getting linked wearables...") devices_url = urls.URLS['devices'].format(user_id=urllib.parse.quote(self.user_id)) @@ -134,6 +137,8 @@ class HuamiAmazfit: raise ValueError("No 'items' parameter in devices data.") devices = device_request['items'] + devices_dict = {} + for idx, wearable in enumerate(devices): if 'macAddress' not in wearable: raise ValueError("No 'macAddress' parameter in device data.") @@ -146,9 +151,11 @@ class HuamiAmazfit: if 'auth_key' not in device_info: raise ValueError("No 'auth_key' parameter in device data.") key_str = device_info['auth_key'] - auth_key = '0x' + (key_str if key_str != '' else '0') + auth_key = '0x' + (key_str if key_str != '' else '00') - print(f"Device {idx+1}. Mac = {mac_address}, auth_key = {auth_key}") + devices_dict[f'{mac_address}'] = auth_key + + return devices_dict def get_gps_data(self): agps_packs = ["AGPS_ALM", "AGPSZIP"] @@ -203,11 +210,21 @@ if __name__ == "__main__": help="Account Password") args = parser.parse_args() + console = Console() + table = Table(show_header=True, header_style="bold") + table.add_column("MAC", style="dim", width=17, justify='center') + table.add_column("auth_key", width=36, justify='center') + device = HuamiAmazfit(method=args.method, email=args.email, password=args.password) device.get_access_token() device.login() - device.get_wearable_auth_keys() + + device_keys = device.get_wearable_auth_keys() + for device_key in device_keys: + table.add_row(device_key, device_keys[device_key]) + console.print(table) + device.get_gps_data() device.logout() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..50d13b6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +argparse +requests +urllib +rich \ No newline at end of file