From 2287839db587eaf895621345e22a6edeed08c5ee Mon Sep 17 00:00:00 2001 From: Kirill Snezhko <4477094+argrento@users.noreply.github.com> Date: Wed, 24 Feb 2021 02:22:05 +0300 Subject: [PATCH] Update readme, fix linter errors --- README.md | 4 ++-- huami_token.py | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c7f868c..02bd168 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ optional arguments: -f, --firmware Request firmware updates. Works only with -b/--bt_keys argument. Extremely dangerous -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 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. 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 the table above. +Use the downloaded files at your own risk! ## Dependencies diff --git a/huami_token.py b/huami_token.py index 3edab0c..7913aa2 100644 --- a/huami_token.py +++ b/huami_token.py @@ -12,7 +12,6 @@ import urllib import argparse import getpass import requests -import hashlib from rich.console import Console from rich.table import Table @@ -186,7 +185,8 @@ class HuamiAmazfit: 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""" fw_url = urls.URLS["fw_updates"] params = urls.PAYLOADS["fw_updates"] @@ -202,24 +202,20 @@ class HuamiAmazfit: response = requests.get(fw_url, params=params, headers=headers) response.raise_for_status() fw_response = response.json() - - msgs = [] links = [] hashes = [] if 'firmwareUrl' in fw_response: - msgs.append('firmware') links.append(fw_response['firmwareUrl']) hashes.append(fw_response['firmwareMd5']) if 'fontUrl' in fw_response: - msgs.append('font') links.append(fw_response['fontUrl']) hashes.append(fw_response['fontMd5']) if not links: print("No updates found!") else: - for msg, link, hash_sum in zip(msgs, links, hashes): + for link, hash_sum in zip(links, hashes): file_name = link.split('/')[-1] print(f"Downloading {file_name}...") with requests.get(link, stream=True) as r: @@ -235,7 +231,7 @@ class HuamiAmazfit: headers = urls.PAYLOADS['agps'] 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}...") response = requests.get(agps_link.format(pack_name=agps_pack_name), headers=headers) response.raise_for_status() @@ -243,7 +239,7 @@ class HuamiAmazfit: if 'fileUrl' not in agps_result: raise ValueError("No 'fileUrl' parameter in files 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) def logout(self) -> None: