kopia lustrzana https://codeberg.org/argrento/huami-token
cache token into json for quick reuse
rodzic
c6c0d7971a
commit
3f03323bf7
|
|
@ -39,6 +39,8 @@ from rich import box
|
||||||
|
|
||||||
import urls
|
import urls
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
class HuamiAmazfit:
|
class HuamiAmazfit:
|
||||||
"""Base class for logging in and receiving auth keys and GPS packs"""
|
"""Base class for logging in and receiving auth keys and GPS packs"""
|
||||||
def __init__(self, method="amazfit", email=None, password=None):
|
def __init__(self, method="amazfit", email=None, password=None):
|
||||||
|
|
@ -279,13 +281,27 @@ class HuamiAmazfit:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
no_logout = None
|
||||||
|
login_method = None
|
||||||
|
login_method_required = True
|
||||||
|
config = {}
|
||||||
|
try:
|
||||||
|
config_file = open("config.json",'r')
|
||||||
|
config = json.load(config_file)
|
||||||
|
config_file.close()
|
||||||
|
login_method_required=False
|
||||||
|
except Exception as e:
|
||||||
|
print ("except",e)
|
||||||
|
login_method_required=True
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Obtain Bluetooth Auth key from Amazfit "
|
parser = argparse.ArgumentParser(description="Obtain Bluetooth Auth key from Amazfit "
|
||||||
"servers and download AGPS data.")
|
"servers and download AGPS data.")
|
||||||
parser.add_argument("-m",
|
parser.add_argument("-m",
|
||||||
"--method",
|
"--method",
|
||||||
choices=["amazfit", "xiaomi"],
|
choices=["amazfit", "xiaomi"],
|
||||||
default="amazfit",
|
default="amazfit",
|
||||||
required=True,
|
required=login_method_required,
|
||||||
help="Login method ")
|
help="Login method ")
|
||||||
parser.add_argument("-e",
|
parser.add_argument("-e",
|
||||||
"--email",
|
"--email",
|
||||||
|
|
@ -342,14 +358,34 @@ if __name__ == "__main__":
|
||||||
if args.firmware and not args.bt_keys:
|
if args.firmware and not args.bt_keys:
|
||||||
parser.error("Can not use -f/--firmware without -b/--bt_keys!")
|
parser.error("Can not use -f/--firmware without -b/--bt_keys!")
|
||||||
|
|
||||||
if args.password is None and args.method == "amazfit":
|
if "login_method" in config.keys():
|
||||||
|
login_method = config["login_method"]
|
||||||
|
else:
|
||||||
|
login_method = args.method
|
||||||
|
|
||||||
|
|
||||||
|
if no_logout == None:
|
||||||
|
no_logout = args.no_logout
|
||||||
|
|
||||||
|
if args.password is None and login_method == "amazfit":
|
||||||
args.password = getpass.getpass()
|
args.password = getpass.getpass()
|
||||||
|
|
||||||
device = HuamiAmazfit(method=args.method,
|
device = HuamiAmazfit(method=login_method,
|
||||||
email=args.email,
|
email=args.email,
|
||||||
password=args.password)
|
password=args.password)
|
||||||
device.get_access_token()
|
|
||||||
device.login()
|
if "user_id" in config.keys():
|
||||||
|
device.user_id = config["user_id"]
|
||||||
|
if "login_token" in config.keys():
|
||||||
|
device.login_token = config["login_token"]
|
||||||
|
if "app_token" in config.keys():
|
||||||
|
device.app_token = config["app_token"]
|
||||||
|
if "no_logout" in config.keys():
|
||||||
|
no_logout = config["no_logout"]
|
||||||
|
|
||||||
|
if device.login_token == None and device.app_token == None:
|
||||||
|
device.get_access_token()
|
||||||
|
device.login()
|
||||||
|
|
||||||
wearables = []
|
wearables = []
|
||||||
if args.bt_keys or args.all:
|
if args.bt_keys or args.all:
|
||||||
|
|
@ -379,8 +415,22 @@ if __name__ == "__main__":
|
||||||
if args.gps or args.all:
|
if args.gps or args.all:
|
||||||
device.get_gps_data()
|
device.get_gps_data()
|
||||||
|
|
||||||
if args.no_logout:
|
if no_logout:
|
||||||
print("\nNo logout!")
|
print("\nNo logout!")
|
||||||
print(f"app_token={device.app_token}\nlogin_token={device.login_token}")
|
print(f"app_token={device.app_token}\nlogin_token={device.login_token}")
|
||||||
|
config = {}
|
||||||
|
config["login_token"] = device.login_token
|
||||||
|
config["app_token"] = device.app_token
|
||||||
|
config["login_method"] = login_method
|
||||||
|
config["no_logout"] = no_logout
|
||||||
|
config["user_id"] = device.user_id
|
||||||
|
|
||||||
|
config['country_code'] = device.country_code
|
||||||
|
config['device_id'] = device.device_id
|
||||||
|
|
||||||
|
f = open("config.json", 'w')
|
||||||
|
json.dump(config, f, indent=4, sort_keys=True)
|
||||||
|
f.close()
|
||||||
else:
|
else:
|
||||||
device.logout()
|
device.logout()
|
||||||
|
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue