From 4267dfcb33c8310cbac533a9d41a3f2e505625b1 Mon Sep 17 00:00:00 2001 From: Karl Date: Tue, 15 Jul 2025 14:40:43 +0100 Subject: [PATCH] account checker --- .vscode/launch.json | 7 +++++ ktvmanager/account_checker.py | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 ktvmanager/account_checker.py diff --git a/.vscode/launch.json b/.vscode/launch.json index 21c801f..dd46c02 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,6 +1,13 @@ { "version": "0.2.0", "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + }, { "name": "Python: Flask", "type": "python", diff --git a/ktvmanager/account_checker.py b/ktvmanager/account_checker.py new file mode 100644 index 0000000..1fcec19 --- /dev/null +++ b/ktvmanager/account_checker.py @@ -0,0 +1,57 @@ +import os +import sys +from dotenv import load_dotenv +import mysql.connector + +# Add the project root to the Python path +project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.append(project_root) +from ktvmanager.lib.encryption import decrypt_password +from ktvmanager.lib.checker import single_account_check +from ktvmanager.lib.get_urls import get_latest_urls_from_dns + +def get_all_accounts(db_connection): + cursor = db_connection.cursor(dictionary=True) + query = "SELECT * FROM userAccounts where userId = 1" + cursor.execute(query) + accounts = cursor.fetchall() + cursor.close() + return accounts + +def main(): + load_dotenv() + + db_connection = mysql.connector.connect( + host=os.getenv("DBHOST"), + user=os.getenv("DBUSER"), + password=os.getenv("DBPASS"), + database=os.getenv("DATABASE"), + port=os.getenv("DBPORT") + ) + + accounts = get_all_accounts(db_connection) + stream_urls = get_latest_urls_from_dns() + + for account in accounts: + try: + decrypted_password = decrypt_password(account['password']) + except Exception as e: + print(f"Could not decrypt password for {account['username']}: {e}") + continue + + account_data = { + "username": account['username'], + "password": decrypted_password + } + + result = single_account_check(account_data, stream_urls) + + if result: + print(f"Account {account['username']} on stream {account['stream']} is VALID.") + else: + print(f"Account {account['username']} on stream {account['stream']} is INVALID.") + + db_connection.close() + +if __name__ == "__main__": + main() \ No newline at end of file