tooncher 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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):
  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:
  14. engine_path = config['engine_path'] if 'engine_path' in config else None
  15. if engine_path is None:
  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. )
  25. def _init_argparser():
  26. import argparse
  27. argparser = argparse.ArgumentParser(description = None)
  28. argparser.add_argument('username')
  29. argparser.add_argument(
  30. '--config',
  31. '-c',
  32. metavar = 'path',
  33. dest = 'config_path',
  34. help = 'path to config file (default: %(default)s)',
  35. default = os.path.join(os.path.expanduser('~'), '.tooncher'),
  36. )
  37. return argparser
  38. def main(argv):
  39. argparser = _init_argparser()
  40. try:
  41. import argcomplete
  42. argcomplete.autocomplete(argparser)
  43. except ImportError:
  44. pass
  45. args = argparser.parse_args(argv)
  46. run(**vars(args))
  47. return 0
  48. if __name__ == "__main__":
  49. sys.exit(main(sys.argv[1:]))