Skip to content

Commit

Permalink
Cleaned up code and keyboardinterrupt function
Browse files Browse the repository at this point in the history
  • Loading branch information
Derpitron committed Nov 28, 2023
1 parent 2dcb001 commit c65e03c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 8 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from yaml import safe_load as load
import sys

Expand All @@ -19,7 +20,7 @@ def load_configuration(configuration_file_path='user/cfg.yml') -> dict:
:rtype: dict
"""
with open(configuration_file_path, "r") as configuration_file:
logger.debug('Loaded configuration file located at', configuration_file.name)
logger.debug(f'Loaded configuration file located at{os.path.realpath(configuration_file.name)}')
return load(configuration_file)

def userFacing(configuration: dict):
Expand Down Expand Up @@ -71,7 +72,9 @@ def userFacing(configuration: dict):
bootstrap_login_page(driver, configuration)

if __name__ == '__main__':
userFacing(load_configuration())
# Exit procedure taken from: https://stackoverflow.com/a/21144662
logger.info('Halting Program on KeyboardInterrupt')
sys.exit(130)
try:
userFacing(load_configuration())
except KeyboardInterrupt:
# Exit procedure taken from: https://stackoverflow.com/a/21144662
logger.info('Halting Program on KeyboardInterrupt')
sys.exit(130)
16 changes: 12 additions & 4 deletions src/backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Import dependencies and libraries
import os
import time
import secrets
from src.lib.codegen import generate_random_code
Expand Down Expand Up @@ -57,11 +58,16 @@ def bootstrap_browser(
# Go to the appropriate starting page for the mode
landing_url = ''
match configuration['programMode'].lower():
case 'login': landing_url = 'https://www.discord.com/login'
case 'reset': landing_url = 'https://discord.com/reset#token=' + configuration['resetToken']
case 'login':
landing_url = 'https://www.discord.com/login'
driver.get(landing_url)
logger.debug(f'Going to landing page: {landing_url}')
case 'reset':
landing_url = 'https://discord.com/reset#token=' + configuration['resetToken']
driver.get(landing_url)
logger.debug(f'Going to landing page: {landing_url}')
# Go to the required Discord login/landing page
driver.get(landing_url)
logger.debug('Going to landing page:', landing_url)


# Wait 1 second before typing the email and password
driver.implicitly_wait(1)
Expand Down Expand Up @@ -242,6 +248,8 @@ def code_entry(
except KeyboardInterrupt:
session_statistics['elapsedTime'] = time.time() - start_time
print_session_statistics('closed_by_user_keyboard_interrupt', session_statistics)
raise KeyboardInterrupt


def print_session_statistics(
halt_reason: str,
Expand Down

0 comments on commit c65e03c

Please sign in to comment.