initialize.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import argparse
  2. import configparser
  3. import logging
  4. import os.path
  5. import sys
  6. import auth, downloader, logger
  7. def check_config_validity(config):
  8. username = config['pyinstalive']['username']
  9. password = config['pyinstalive']['password']
  10. if not ((len(username) > 0) or (len(password) > 0)):
  11. logger.log("[E] Username or password are not entered correct in config file!", "RED")
  12. return False
  13. return True
  14. def run():
  15. script_version = "2.1.7"
  16. bool_values = {'True', 'False'}
  17. logger.log('PYINSTALIVE DOWNLOADER (SCRIPT v{0!s})'.format(script_version), "GREEN")
  18. logger.seperator("GREEN")
  19. logging.disable(logging.CRITICAL)
  20. config = configparser.ConfigParser()
  21. if os.path.exists('pyinstalive.ini'):
  22. try:
  23. config.read('pyinstalive.ini')
  24. except Exception:
  25. logger.log("[E] Could not read configuration file! Try passing the required arguments manually.", "RED")
  26. logger.seperator("GREEN")
  27. else:
  28. logger.log("[E] Could not find configuration file!", "RED")
  29. logger.seperator("GREEN")
  30. sys.exit(0)
  31. parser = argparse.ArgumentParser(description='Login')
  32. parser.add_argument('-u', '--username', dest='username', type=str, required=False)
  33. parser.add_argument('-p', '--password', dest='password', type=str, required=False)
  34. parser.add_argument('-r', '--record', dest='record', type=str, required=True)
  35. args = parser.parse_args()
  36. if check_config_validity(config):
  37. username = config['pyinstalive']['username']
  38. password = config['pyinstalive']['password']
  39. try:
  40. show_cookie_expiry = config['pyinstalive']['show_cookie_expiry']
  41. if not config['pyinstalive']['show_cookie_expiry'].title() in bool_values:
  42. logger.log("[W] Invalid setting detected for show_cookie_expiry, falling back to default value (True)", "YELLOW")
  43. show_cookie_expiry = 'True'
  44. except:
  45. logger.log("[W] Invalid setting detected for show_cookie_expiry, falling back to default value (True)", "YELLOW")
  46. show_cookie_expiry = 'True'
  47. try:
  48. save_path = config['pyinstalive']['save_path']
  49. if (os.path.exists(save_path)):
  50. pass
  51. else:
  52. logger.log("[W] Invalid setting detected for save_path, falling back to location: " + os.getcwd(), "YELLOW")
  53. save_path = os.getcwd()
  54. if not save_path.endswith('/'):
  55. save_path = save_path + '/'
  56. except:
  57. logger.log("[W] Invalid setting detected for save_path, falling back to location: " + os.getcwd(), "YELLOW")
  58. save_path = os.getcwd()
  59. if (args.username is not None) and (args.password is not None):
  60. api = auth.login(args.username, args.password, show_cookie_expiry)
  61. else:
  62. api = auth.login(username, password, show_cookie_expiry)
  63. downloader.main(api, args.record, save_path)
  64. else:
  65. logger.log("[E] The configuration file is not valid. Please check your configuration settings and try again.", "RED")
  66. logger.seperator("GREEN")
  67. sys.exit(0)