mirror of
https://codeberg.org/vanous/huafetcher.git
synced 2025-01-10 07:02:03 +01:00
rotate agps servers in case of 401 error
This commit is contained in:
parent
a40b8c9bbe
commit
1905801d2d
@ -28,7 +28,7 @@ source.exclude_dirs = tests, bin, screenshots
|
||||
#source.exclude_patterns = license,images/*/*.jpg
|
||||
|
||||
# (str) Application versioning (method 1)
|
||||
version = 0.18
|
||||
version = 0.19
|
||||
|
||||
# (str) Application versioning (method 2)
|
||||
# version.regex = __version__ = ['"](.*)['"]
|
||||
|
@ -170,14 +170,22 @@ class HuamiAmazfit:
|
||||
|
||||
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()
|
||||
servers=['api-mifit-us2', 'api-mifit-de2', 'api-mifit-cn2', 'api-mifit-sg2','api-mifit']
|
||||
for server in servers:
|
||||
print(f"trying server: {server}")
|
||||
response = requests.get(agps_link.format(pack_name=agps_pack_name, server=server), headers=headers)
|
||||
print(f"status: {response.status_code}")
|
||||
#response.raise_for_status()
|
||||
if response.status_code == 401:
|
||||
print("try new server")
|
||||
continue
|
||||
agps_result = response.json()[0]
|
||||
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[pack_idx], 'wb') as gps_file:
|
||||
shutil.copyfileobj(request.raw, gps_file)
|
||||
break
|
||||
|
||||
def logout(self):
|
||||
logout_url = urls.URLS['logout']
|
||||
|
2
urls.py
2
urls.py
@ -28,7 +28,7 @@ URLS = {
|
||||
'tokens_amazfit': 'https://api-user.huami.com/registrations/{user_email}/tokens',
|
||||
'login_amazfit': 'https://account.huami.com/v2/client/login',
|
||||
'devices': 'https://api-mifit-us2.huami.com/users/{user_id}/devices',
|
||||
'agps': 'https://api-mifit.huami.com/apps/com.huami.midong/fileTypes/{pack_name}/files',
|
||||
'agps': 'https://{server}.huami.com/apps/com.huami.midong/fileTypes/{pack_name}/files',
|
||||
'data_short': 'https://api-mifit-us2.huami.com/users/{user_id}/deviceTypes/4/data',
|
||||
'logout': 'https://account-us2.huami.com/v1/client/logout',
|
||||
'fw_updates': 'https://api-mifit-us2.huami.com/devices/ALL/hasNewVersion'
|
||||
|
Loading…
Reference in New Issue
Block a user