diff --git a/assets/level.txt b/assets/level.txt index 56a6051..d8263ee 100644 --- a/assets/level.txt +++ b/assets/level.txt @@ -1 +1 @@ -1 \ No newline at end of file +2 \ No newline at end of file diff --git a/assets/questions.txt b/assets/questions.txt index 25050ac..d893efe 100644 --- a/assets/questions.txt +++ b/assets/questions.txt @@ -26,4 +26,43 @@ How do you list kernel modules?|lsmod|modprobe -l|dmesg|1 How do you analyze CPU usage?|top|htop|vmstat|1 Which command lists active TCP connections?|netstat -tulpn|ss -tulpn|lsof -i|1 How do you stop a systemd service?|systemctl stop|systemctl disable|systemctl restart|1 -How do you check the DNS cache?|systemd-resolve --statistics|systemctl dns|dns cache|1 \ No newline at end of file +How do you check the DNS cache?|systemd-resolve --statistics|systemctl dns|dns cache|1 +What command is used to list all files in a directory?|ls -l|ls -a|ls -la|ls -lh|2 +What command is used to change the current directory?|cd|chdir|change|dir|1 +What command is used to display the current working directory?|pwd|cwd|dir|ls|1 +What command is used to create a new directory?|mkdir|newdir|createdir|makedir|1 +What command is used to remove a file?|rm|delete|remove|erase|1 +What command is used to copy files?|cp|copy|duplicate|move|1 +What command is used to move files?|mv|move|transfer|shift|1 +What command is used to display the contents of a file?|cat|show|display|view|1 +What command is used to search for a pattern in a file?|grep|search|find|look|1 +What command is used to display the first few lines of a file?|head|top|start|begin|1 +What command is used to display the last few lines of a file?|tail|end|finish|bottom|1 +What command is used to display the manual page for a command?|man|help|info|guide|1 +What command is used to change file permissions?|chmod|chperm|chown|chattr|1 +What command is used to change file ownership?|chown|chperm|chmod|chattr|1 +What command is used to display disk usage?|du|df|disk|usage|1 +What command is used to display free disk space?|df|du|disk|free|1 +What command is used to display system information?|uname|sysinfo|info|system|1 +What command is used to display running processes?|ps|proc|process|run|1 +What command is used to terminate a process?|kill|terminate|end|stop|1 +What command is used to display network configuration?|ifconfig|netconfig|network|config|1 +What command is used to display the routing table?|route|netstat|traceroute|path|1 +What command is used to display open network connections?|netstat|conn|connections|open|1 +What command is used to display the hostname?|hostname|host|name|display|1 +What command is used to change the hostname?|hostnamectl|hostctl|namectl|changehost|1 +What command is used to display the current date and time?|date|time|datetime|now|1 +What command is used to set the system date and time?|date -s|time -s|datetime -s|setdate|1 +What command is used to display the system uptime?|uptime|time|sysuptime|up|1 +What command is used to reboot the system?|reboot|restart|shutdown -r|boot|1 +What command is used to shut down the system?|shutdown|halt|poweroff|stop|1 +What command is used to display the contents of a directory?|ls|dir|list|show|1 +What command is used to display the current user's ID?|id|userid|uid|whoami|1 +What command is used to switch to another user?|su|switch|user|login|1 +What command is used to display the system's kernel version?|uname -r|kernel|version|sysver|1 +What command is used to display the system's architecture?|uname -m|arch|architecture|sysarch|1 +What command is used to display the system's release information?|uname -a|release|info|sysinfo|1 +What command is used to display the system's hardware information?|lshw|hwinfo|hardware|sysinfo|1 +What command is used to display the system's memory usage?|free|mem|memory|usage|1 +What command is used to display the system's CPU usage?|top|cpu|usage|syscpu|1 +What command is used to display the system's load average?|uptime|load|average|sysload|1 \ No newline at end of file diff --git a/assets/session.log b/assets/session.log index a860e87..a7ded3b 100644 --- a/assets/session.log +++ b/assets/session.log @@ -19,3 +19,35 @@ Session end: 2025-01-07 22:05:32 Session start: 2025-01-07 22:07:04 XP and level updated: 50 XP, Level 1 Session end: 2025-01-07 22:07:33 +Session start: 2025-01-07 23:37:33 +XP and level updated: 45 XP, Level 1 +XP and level updated: 55 XP, Level 1 +Session end: 2025-01-07 23:40:16 +Session start: 2025-01-07 23:40:32 +XP and level updated: 65 XP, Level 1 +Session end: 2025-01-07 23:40:48 +Session start: 2025-01-07 23:42:08 +XP and level updated: 75 XP, Level 1 +Session end: 2025-01-07 23:42:41 +Session start: 2025-01-07 23:44:30 +XP and level updated: 85 XP, Level 1 +Session start: 2025-01-07 23:46:25 +XP and level updated: 95 XP, Level 1 +Session end: 2025-01-07 23:46:46 +Session start: 2025-01-07 23:49:54 +XP and level updated: 5 XP, Level 2 +Session end: 2025-01-07 23:51:02 +Session start: 2025-01-07 23:53:24 +XP and level updated: 0 XP, Level 2 +Session end: 2025-01-07 23:53:50 +Session start: 2025-01-07 23:56:05 +XP and level updated: 0 XP, Level 2 +Session end: 2025-01-07 23:56:40 +Session start: 2025-01-07 23:58:57 +Session start: 2025-01-08 00:00:35 +Session start: 2025-01-08 00:04:38 +XP and level updated: 0 XP, Level 2 +Session end: 2025-01-08 00:04:59 +Session start: 2025-01-08 00:11:09 +XP and level updated: 10 XP, Level 2 +Session end: 2025-01-08 00:11:34 diff --git a/assets/xp.txt b/assets/xp.txt index c5b431b..9a03714 100644 --- a/assets/xp.txt +++ b/assets/xp.txt @@ -1 +1 @@ -50 \ No newline at end of file +10 \ No newline at end of file diff --git a/main.py b/main.py index 83144fe..a78234a 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,8 @@ import psutil import tkinter as tk from tkinter import messagebox import random +import sys +import subprocess # Utility functions def initialize_assets(assets_dir, xp_file, level_file, session_log, total_time_file, questions_file): @@ -35,16 +37,15 @@ def display_summary(total_time_file, xp_file, level_file): with open(level_file, 'r') as f: level = int(f.read().strip()) hours, minutes = divmod(total_time, 60) - print(f"Welcome to the RHEL Learning Script!") - print(f"Total session time: {hours} hours and {minutes} minutes.") - print(f"Current Level: {level}") - print(f"Current XP: {xp}") - print() + return total_time, xp, level def kill_steam(): for proc in psutil.process_iter(): - if proc.name() == "steam.exe": - proc.kill() + try: + if 'steam' in proc.name().lower(): + proc.kill() + except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): + pass def update_xp(xp_file, level_file, session_log, correct): with open(xp_file, 'r') as f: @@ -58,15 +59,16 @@ def update_xp(xp_file, level_file, session_log, correct): if new_xp >= level * 100: level += 1 new_xp -= (level - 1) * 100 - print(f"LEVEL UP! You are now Level {level}!") + messagebox.showinfo("LEVEL UP!", f"LEVEL UP! You are now Level {level}!") with open(xp_file, 'w') as f: f.write(str(new_xp)) with open(level_file, 'w') as f: f.write(str(level)) with open(session_log, 'a') as f: f.write(f"XP and level updated: {new_xp} XP, Level {level}\n") + return new_xp, level -def show_timer(minutes, questions_file, session_log): +def show_timer(minutes, questions_file, session_log, total_time, xp, level): def update_timer(): nonlocal seconds_left if seconds_left > 0: @@ -85,10 +87,18 @@ def show_timer(minutes, questions_file, session_log): selected_answer = answer_var.get() if selected_answer == correct_answer: messagebox.showinfo("Correct!", "You selected the correct answer.") - update_xp(XP_FILE, LEVEL_FILE, SESSION_LOG, correct=True) + new_xp, new_level = update_xp(XP_FILE, LEVEL_FILE, SESSION_LOG, correct=True) else: messagebox.showinfo("Incorrect", "You selected the wrong answer.") - update_xp(XP_FILE, LEVEL_FILE, SESSION_LOG, correct=False) + new_xp, new_level = update_xp(XP_FILE, LEVEL_FILE, SESSION_LOG, correct=False) + for button in radio_buttons: + button.config(state=tk.DISABLED) + xp_label.config(text=f"XP: {new_xp}") + level_label.config(text=f"Level: {new_level}") + + def periodic_kill_steam(): + kill_steam() + root.after(10000, periodic_kill_steam) # Schedule to run every 10 seconds root = tk.Tk() root.title("RHEL Learning Timer") @@ -98,8 +108,18 @@ def show_timer(minutes, questions_file, session_log): timer_label = tk.Label(root, text=f"Time left: {minutes:02}:00:00", font=("Helvetica", 16)) timer_label.pack(pady=20) + xp_label = tk.Label(root, text=f"XP: {xp}", font=("Helvetica", 14)) + xp_label.pack(pady=5) + + level_label = tk.Label(root, text=f"Level: {level}", font=("Helvetica", 14)) + level_label.pack(pady=5) + + total_time_label = tk.Label(root, text=f"Total session time: {total_time // 60} hours and {total_time % 60} minutes", font=("Helvetica", 14)) + total_time_label.pack(pady=5) + with open(questions_file, 'r') as f: questions = f.readlines() + random.shuffle(questions) # Shuffle the questions to ensure randomness question = random.choice(questions).strip() question_text, *answers, correct_answer = question.split('|') @@ -108,17 +128,28 @@ def show_timer(minutes, questions_file, session_log): question_label.pack(pady=10) answer_var = tk.StringVar(value="") + radio_buttons = [] for idx, answer in enumerate(answers, start=1): radio_button = tk.Radiobutton(root, text=answer, variable=answer_var, value=str(idx), font=("Helvetica", 12)) radio_button.pack(anchor='w') + radio_buttons.append(radio_button) submit_button = tk.Button(root, text="Submit", command=check_answer, font=("Helvetica", 12)) submit_button.pack(pady=10) root.after(1000, update_timer) + root.after(10000, periodic_kill_steam) # Start the periodic kill_steam function root.mainloop() +def open_firefox(url): + print(f"Attempting to open Firefox with URL: {url}") + if 'DISPLAY' in os.environ: + subprocess.Popen(['firefox', '--new-window', url], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + print("Firefox opened successfully.") + else: + print("No graphical environment detected. Skipping browser opening.") + # Constants SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) ASSETS_DIR = os.path.join(SCRIPT_DIR, 'assets') @@ -138,17 +169,19 @@ def main(): log_session(SESSION_LOG, "start") # Display session summary - display_summary(TOTAL_TIME_FILE, XP_FILE, LEVEL_FILE) + total_time, xp, level = display_summary(TOTAL_TIME_FILE, XP_FILE, LEVEL_FILE) - # Start killing Steam processes in the background - kill_steam() + # Open Firefox to the specified URL + open_firefox(URL) # Start session - print("Starting RHEL Learning Session...") - show_timer(TIMER_MINUTES, QUESTIONS_FILE, SESSION_LOG) + show_timer(TIMER_MINUTES, QUESTIONS_FILE, SESSION_LOG, total_time, xp, level) # Log session end log_session(SESSION_LOG, "end") if __name__ == "__main__": - main() + if len(sys.argv) > 1 and sys.argv[1] == "kill_steam": + kill_steam() + else: + main()