initialize.py 2.8 KB

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