mirror of
https://codeberg.org/vanous/huafetcher.git
synced 2025-01-10 15:12:01 +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
|
#source.exclude_patterns = license,images/*/*.jpg
|
||||||
|
|
||||||
# (str) Application versioning (method 1)
|
# (str) Application versioning (method 1)
|
||||||
version = 0.18
|
version = 0.19
|
||||||
|
|
||||||
# (str) Application versioning (method 2)
|
# (str) Application versioning (method 2)
|
||||||
# version.regex = __version__ = ['"](.*)['"]
|
# version.regex = __version__ = ['"](.*)['"]
|
||||||
|
@ -170,14 +170,22 @@ class HuamiAmazfit:
|
|||||||
|
|
||||||
for pack_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)
|
servers=['api-mifit-us2', 'api-mifit-de2', 'api-mifit-cn2', 'api-mifit-sg2','api-mifit']
|
||||||
response.raise_for_status()
|
for server in servers:
|
||||||
agps_result = response.json()[0]
|
print(f"trying server: {server}")
|
||||||
if 'fileUrl' not in agps_result:
|
response = requests.get(agps_link.format(pack_name=agps_pack_name, server=server), headers=headers)
|
||||||
raise ValueError("No 'fileUrl' parameter in files request.")
|
print(f"status: {response.status_code}")
|
||||||
with requests.get(agps_result['fileUrl'], stream=True) as request:
|
#response.raise_for_status()
|
||||||
with open(agps_file_names[pack_idx], 'wb') as gps_file:
|
if response.status_code == 401:
|
||||||
shutil.copyfileobj(request.raw, gps_file)
|
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):
|
def logout(self):
|
||||||
logout_url = urls.URLS['logout']
|
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',
|
'tokens_amazfit': 'https://api-user.huami.com/registrations/{user_email}/tokens',
|
||||||
'login_amazfit': 'https://account.huami.com/v2/client/login',
|
'login_amazfit': 'https://account.huami.com/v2/client/login',
|
||||||
'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.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',
|
'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',
|
||||||
'fw_updates': 'https://api-mifit-us2.huami.com/devices/ALL/hasNewVersion'
|
'fw_updates': 'https://api-mifit-us2.huami.com/devices/ALL/hasNewVersion'
|
||||||
|
Loading…
Reference in New Issue
Block a user