tooncher 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python3
  2. # PYTHON_ARGCOMPLETE_OK
  3. import os
  4. import sys
  5. import tooncher
  6. import yaml
  7. def run(username, config_path, engine_path=None, validate_ssl_certs=True):
  8. if os.path.exists(config_path):
  9. with open(config_path) as f:
  10. config = yaml.load(f.read())
  11. else:
  12. config = {}
  13. if engine_path is None and 'engine_path' in config:
  14. engine_path = config['engine_path']
  15. else:
  16. raise Exception('missing path to toontown engine')
  17. accounts = config['accounts'] if 'accounts' in config else []
  18. for account in accounts:
  19. if account['username'] == username:
  20. tooncher.launch(
  21. engine_path=engine_path,
  22. username=account['username'],
  23. password=account['password'],
  24. validate_ssl_certs=validate_ssl_certs,
  25. )
  26. def _init_argparser():
  27. import argparse
  28. argparser = argparse.ArgumentParser(description=None)
  29. argparser.add_argument('username')
  30. argparser.add_argument(
  31. '--config',
  32. '-c',
  33. metavar='path',
  34. dest='config_path',
  35. help='path to config file (default: %(default)s)',
  36. default=os.path.join(os.path.expanduser('~'), '.tooncher'),
  37. )
  38. argparser.add_argument(
  39. '--no-ssl-cert-validation',
  40. '-k',
  41. dest='validate_ssl_certs',
  42. help='do not validate ssl certificates',
  43. action='store_false',
  44. )
  45. return argparser
  46. def main(argv):
  47. argparser = _init_argparser()
  48. try:
  49. import argcomplete
  50. argcomplete.autocomplete(argparser)
  51. except ImportError:
  52. pass
  53. args = argparser.parse_args(argv)
  54. run(**vars(args))
  55. return 0
  56. if __name__ == "__main__":
  57. sys.exit(main(sys.argv[1:]))