kopia lustrzana https://codeberg.org/argrento/huami-token
Update readme, fix linter errors
rodzic
0f9d6f6aab
commit
2287839db5
|
@ -45,7 +45,7 @@ optional arguments:
|
||||||
-f, --firmware Request firmware updates. Works only with -b/--bt_keys
|
-f, --firmware Request firmware updates. Works only with -b/--bt_keys
|
||||||
argument. Extremely dangerous
|
argument. Extremely dangerous
|
||||||
-a, --all Do everything: get bluetooth tokens, download A-GPS
|
-a, --all Do everything: get bluetooth tokens, download A-GPS
|
||||||
files
|
files. But do NOT download firmware updates
|
||||||
-n, --no_logout Do not logout, keep active session and display app
|
-n, --no_logout Do not logout, keep active session and display app
|
||||||
token and access token
|
token and access token
|
||||||
```
|
```
|
||||||
|
@ -124,10 +124,10 @@ I am not responsible for any of problems that might arise.
|
||||||
|
|
||||||
Can be enabled with `-f/--firmware` argument. Will work only with `-b/--bt_keys` argument.
|
Can be enabled with `-f/--firmware` argument. Will work only with `-b/--bt_keys` argument.
|
||||||
You should input the ID of a device, or `-1` to check for all.
|
You should input the ID of a device, or `-1` to check for all.
|
||||||
|
|
||||||
Script will try to find updates for the firmware and the font pack for the device from
|
Script will try to find updates for the firmware and the font pack for the device from
|
||||||
the table above.
|
the table above.
|
||||||
|
|
||||||
|
Use the downloaded files at your own risk!
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import urllib
|
||||||
import argparse
|
import argparse
|
||||||
import getpass
|
import getpass
|
||||||
import requests
|
import requests
|
||||||
import hashlib
|
|
||||||
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
|
@ -186,7 +185,8 @@ class HuamiAmazfit:
|
||||||
|
|
||||||
return _wearables
|
return _wearables
|
||||||
|
|
||||||
def get_firmware(self, _wearable: dict) -> None:
|
@staticmethod
|
||||||
|
def get_firmware(_wearable: dict) -> None:
|
||||||
"""Check and download updates for the furmware and fonts"""
|
"""Check and download updates for the furmware and fonts"""
|
||||||
fw_url = urls.URLS["fw_updates"]
|
fw_url = urls.URLS["fw_updates"]
|
||||||
params = urls.PAYLOADS["fw_updates"]
|
params = urls.PAYLOADS["fw_updates"]
|
||||||
|
@ -202,24 +202,20 @@ class HuamiAmazfit:
|
||||||
response = requests.get(fw_url, params=params, headers=headers)
|
response = requests.get(fw_url, params=params, headers=headers)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
fw_response = response.json()
|
fw_response = response.json()
|
||||||
|
|
||||||
msgs = []
|
|
||||||
links = []
|
links = []
|
||||||
hashes = []
|
hashes = []
|
||||||
|
|
||||||
if 'firmwareUrl' in fw_response:
|
if 'firmwareUrl' in fw_response:
|
||||||
msgs.append('firmware')
|
|
||||||
links.append(fw_response['firmwareUrl'])
|
links.append(fw_response['firmwareUrl'])
|
||||||
hashes.append(fw_response['firmwareMd5'])
|
hashes.append(fw_response['firmwareMd5'])
|
||||||
if 'fontUrl' in fw_response:
|
if 'fontUrl' in fw_response:
|
||||||
msgs.append('font')
|
|
||||||
links.append(fw_response['fontUrl'])
|
links.append(fw_response['fontUrl'])
|
||||||
hashes.append(fw_response['fontMd5'])
|
hashes.append(fw_response['fontMd5'])
|
||||||
|
|
||||||
if not links:
|
if not links:
|
||||||
print("No updates found!")
|
print("No updates found!")
|
||||||
else:
|
else:
|
||||||
for msg, link, hash_sum in zip(msgs, links, hashes):
|
for link, hash_sum in zip(links, hashes):
|
||||||
file_name = link.split('/')[-1]
|
file_name = link.split('/')[-1]
|
||||||
print(f"Downloading {file_name}...")
|
print(f"Downloading {file_name}...")
|
||||||
with requests.get(link, stream=True) as r:
|
with requests.get(link, stream=True) as r:
|
||||||
|
@ -235,7 +231,7 @@ class HuamiAmazfit:
|
||||||
headers = urls.PAYLOADS['agps']
|
headers = urls.PAYLOADS['agps']
|
||||||
headers['apptoken'] = self.app_token
|
headers['apptoken'] = self.app_token
|
||||||
|
|
||||||
for idx, agps_pack_name in enumerate(agps_packs):
|
for pack_idx, agps_pack_name in enumerate(agps_packs):
|
||||||
print(f"Downloading {agps_pack_name}...")
|
print(f"Downloading {agps_pack_name}...")
|
||||||
response = requests.get(agps_link.format(pack_name=agps_pack_name), headers=headers)
|
response = requests.get(agps_link.format(pack_name=agps_pack_name), headers=headers)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
@ -243,7 +239,7 @@ class HuamiAmazfit:
|
||||||
if 'fileUrl' not in agps_result:
|
if 'fileUrl' not in agps_result:
|
||||||
raise ValueError("No 'fileUrl' parameter in files request.")
|
raise ValueError("No 'fileUrl' parameter in files request.")
|
||||||
with requests.get(agps_result['fileUrl'], stream=True) as request:
|
with requests.get(agps_result['fileUrl'], stream=True) as request:
|
||||||
with open(agps_file_names[idx], 'wb') as gps_file:
|
with open(agps_file_names[pack_idx], 'wb') as gps_file:
|
||||||
shutil.copyfileobj(request.raw, gps_file)
|
shutil.copyfileobj(request.raw, gps_file)
|
||||||
|
|
||||||
def logout(self) -> None:
|
def logout(self) -> None:
|
||||||
|
|
Ładowanie…
Reference in New Issue