pyinstalive.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import argparse
  2. import logging
  3. import os.path
  4. import configparser
  5. import sys
  6. import auth, downloader, logger
  7. def run():
  8. logging.disable(logging.CRITICAL)
  9. config = configparser.ConfigParser()
  10. if os.path.exists('pyinstalive.ini'):
  11. try:
  12. config.read('pyinstalive.ini')
  13. except Exception as e:
  14. logger.log("[E] Could not read configuration file! Try passing the required arguments manually.", "RED")
  15. else:
  16. logger.log("[E] Could not find configuration file! Exiting...", "RED")
  17. sys.exit(0)
  18. parser = argparse.ArgumentParser(description='Login')
  19. parser.add_argument('-u', '--username', dest='username', type=str, required=False)
  20. parser.add_argument('-p', '--password', dest='password', type=str, required=False)
  21. parser.add_argument('-r', '--record', dest='record', type=str, required=True)
  22. args = parser.parse_args()
  23. if (args.username is not None) and (args.password is not None):
  24. api = auth.login(args.username, args.password)
  25. else:
  26. api = auth.login(config['pyinstalive']['username'], config['pyinstalive']['password'])
  27. savePath = config['pyinstalive']['save_path']
  28. if not savePath.endswith('/'):
  29. savePath = savePath + '/'
  30. if (os.path.exists(savePath)):
  31. downloader.main(api, args.record, savePath)
  32. else:
  33. logger.log("[W] Invalid save path was specified! Falling back to location: " + os.getcwd(), "RED")
  34. downloader.main(api, args.record, os.getcwd())