initialize.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. script_version = "2.1.5"
  9. logger.log('PYINSTALIVE DOWNLOADER (SCRIPT v{0!s})'.format(script_version), "GREEN")
  10. logger.seperator("GREEN")
  11. logging.disable(logging.CRITICAL)
  12. config = configparser.ConfigParser()
  13. if os.path.exists('pyinstalive.ini'):
  14. try:
  15. config.read('pyinstalive.ini')
  16. except Exception as e:
  17. logger.log("[E] Could not read configuration file! Try passing the required arguments manually.", "RED")
  18. logger.seperator("GREEN")
  19. else:
  20. logger.log("[E] Could not find configuration file!", "RED")
  21. logger.seperator("GREEN")
  22. sys.exit(0)
  23. parser = argparse.ArgumentParser(description='Login')
  24. parser.add_argument('-u', '--username', dest='username', type=str, required=False)
  25. parser.add_argument('-p', '--password', dest='password', type=str, required=False)
  26. parser.add_argument('-r', '--record', dest='record', type=str, required=True)
  27. args = parser.parse_args()
  28. if (args.username is not None) and (args.password is not None):
  29. api = auth.login(args.username, args.password, config['pyinstalive']['show_cookie_expiry'].title())
  30. else:
  31. api = auth.login(config['pyinstalive']['username'], config['pyinstalive']['password'], config['pyinstalive']['show_cookie_expiry'].title())
  32. save_path = config['pyinstalive']['save_path']
  33. if not save_path.endswith('/'):
  34. save_path = save_path + '/'
  35. if (os.path.exists(save_path)):
  36. downloader.main(api, args.record, save_path)
  37. else:
  38. logger.log("[W] Invalid save path was specified! Falling back to location: " + os.getcwd(), "RED")
  39. downloader.main(api, args.record, os.getcwd())