65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Main entrypoint for auto-huami-token."""
|
|
|
|
import sys
|
|
from argparse import ArgumentError
|
|
|
|
from huami_token.zepp import LogoutError, Path, ZeppClient, ZeppSession
|
|
from huami_token.helpers import build_gps_uihh
|
|
|
|
from .args_handler import ArgsHandler
|
|
from .config_error import ConfigError
|
|
from .config_handler import ConfigHandler
|
|
|
|
|
|
def main() -> int:
|
|
handler = ArgsHandler()
|
|
try:
|
|
args = handler.parse_args(sys.argv[1:])
|
|
except ArgumentError as e:
|
|
print(e.message)
|
|
print(handler.print_help())
|
|
exit(4)
|
|
|
|
try:
|
|
config = ConfigHandler(args, "auto-huami-token")
|
|
except ConfigError:
|
|
print(
|
|
"Neither -k, -a or targets where provided and no config file containing targets could be found"
|
|
)
|
|
exit(3)
|
|
|
|
if args.setup:
|
|
exit()
|
|
|
|
config.log.debug("Initiating run")
|
|
|
|
session = ZeppSession(username=args.email, password=args.password)
|
|
session.login()
|
|
client = ZeppClient(session)
|
|
|
|
if args.keys:
|
|
devices = client.get_devices()
|
|
for i, device in enumerate(devices):
|
|
active = "Yes" if device.active else "No"
|
|
print(f"Device {i}:")
|
|
print(f" MAC: {device.mac}, Active: {active}")
|
|
print(f" Key: 0x{device.auth_key}")
|
|
|
|
if args.gps:
|
|
output_dir = Path(config.target_dir)
|
|
client.download_gps_data(output_dir)
|
|
build_gps_uihh(base_folder=output_dir)
|
|
|
|
try:
|
|
session.logout()
|
|
config.log.info("\nLogged out.")
|
|
return 0
|
|
except LogoutError:
|
|
print("\nError logging out.")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|