diff --git a/src/utils/__pycache__/assets.cpython-312.pyc b/__pycache__/assets.cpython-312.pyc similarity index 100% rename from src/utils/__pycache__/assets.cpython-312.pyc rename to __pycache__/assets.cpython-312.pyc diff --git a/src/utils/__pycache__/session.cpython-312.pyc b/__pycache__/session.cpython-312.pyc similarity index 100% rename from src/utils/__pycache__/session.cpython-312.pyc rename to __pycache__/session.cpython-312.pyc diff --git a/src/utils/__pycache__/steam.cpython-312.pyc b/__pycache__/steam.cpython-312.pyc similarity index 100% rename from src/utils/__pycache__/steam.cpython-312.pyc rename to __pycache__/steam.cpython-312.pyc diff --git a/src/utils/__pycache__/timer.cpython-312.pyc b/__pycache__/timer.cpython-312.pyc similarity index 100% rename from src/utils/__pycache__/timer.cpython-312.pyc rename to __pycache__/timer.cpython-312.pyc diff --git a/src/utils/__pycache__/xp.cpython-312.pyc b/__pycache__/xp.cpython-312.pyc similarity index 100% rename from src/utils/__pycache__/xp.cpython-312.pyc rename to __pycache__/xp.cpython-312.pyc diff --git a/src/utils/assets.py b/assets.py similarity index 100% rename from src/utils/assets.py rename to assets.py diff --git a/assets/level.txt b/assets/level.txt index 8ddbb35..56a6051 100644 --- a/assets/level.txt +++ b/assets/level.txt @@ -1 +1 @@ -/home/alex/git/rhel_learning/assets/level.txt +1 \ No newline at end of file diff --git a/assets/questions.txt b/assets/questions.txt index d235381..25050ac 100644 --- a/assets/questions.txt +++ b/assets/questions.txt @@ -26,5 +26,4 @@ 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 - +How do you check the DNS cache?|systemd-resolve --statistics|systemctl dns|dns cache|1 \ No newline at end of file diff --git a/assets/session.log b/assets/session.log index e912d80..a860e87 100644 --- a/assets/session.log +++ b/assets/session.log @@ -1,39 +1,21 @@ -Session started: 2025-01-04 19:37:40 -Session started: 2025-01-07 19:20:39 -Session started: 2025-01-07 19:21:53 -Session started: 2025-01-07 19:24:51 -Session started: 2025-01-07 19:28:28 -Session started: 2025-01-07 19:28:44 -Session started: 2025-01-07 19:29:50 -Session started: 2025-01-07 20:02:03 -How do you analyze CPU usage?|Wrong +Session start: 2025-01-07 21:54:54 +Session start: 2025-01-07 21:57:48 XP and level updated: 10 XP, Level 1 -Session ended: 2025-01-07 20:02:06, Duration: 20 minutes -Session started: 2025-01-07 20:03:24 -How do you view swap usage?|Wrong +Session end: 2025-01-07 21:58:15 +Session start: 2025-01-07 21:59:58 XP and level updated: 20 XP, Level 1 -Session ended: 2025-01-07 20:03:26, Duration: 20 minutes -Session started: 2025-01-07 20:08:22 -How do you reload firewalld rules?|Wrong +Session end: 2025-01-07 22:00:04 +Session start: 2025-01-07 22:01:15 XP and level updated: 30 XP, Level 1 -Session ended: 2025-01-07 20:08:24, Duration: 20 minutes -Session started: 2025-01-07 20:09:27 -How do you change file ownership?|Wrong -XP and level updated: 40 XP, Level /home/alex/git/rhel_learning/assets/level.txt -Session ended: 2025-01-07 20:09:29, Duration: 20 minutes -Session started: 2025-01-07 20:10:54 -Which command lists all active SELinux booleans?|Wrong -XP and level updated: 50 XP, Level /home/alex/git/rhel_learning/assets/level.txt -Session ended: 2025-01-07 20:10:56, Duration: 20 minutes -Session started: 2025-01-07 20:14:10 -XP and level updated: 60 XP, Level /home/alex/git/rhel_learning/assets/level.txt -Session ended: 2025-01-07 20:14:12, Duration: 20 minutes -Session started: 2025-01-07 20:15:35 -XP and level updated: 70 XP, Level /home/alex/git/rhel_learning/assets/level.txt -Session ended: 2025-01-07 20:15:38, Duration: 20 minutes -Session started: 2025-01-07 20:15:48 -XP and level updated: 80 XP, Level /home/alex/git/rhel_learning/assets/level.txt -Session ended: 2025-01-07 20:15:51, Duration: 20 minutes -Session started: 2025-01-07 21:40:49 -XP and level updated: 90 XP, Level /home/alex/git/rhel_learning/assets/level.txt -Session ended: 2025-01-07 21:40:51, Duration: 20 minutes +Session end: 2025-01-07 22:01:23 +Session start: 2025-01-07 22:02:38 +XP and level updated: 40 XP, Level 1 +Session end: 2025-01-07 22:03:05 +Session start: 2025-01-07 22:05:06 +XP and level updated: 35 XP, Level 1 +XP and level updated: 30 XP, Level 1 +XP and level updated: 40 XP, Level 1 +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 diff --git a/assets/total_time.txt b/assets/total_time.txt index 08839f6..c227083 100644 --- a/assets/total_time.txt +++ b/assets/total_time.txt @@ -1 +1 @@ -200 +0 \ No newline at end of file diff --git a/assets/xp.txt b/assets/xp.txt index d61f00d..c5b431b 100644 --- a/assets/xp.txt +++ b/assets/xp.txt @@ -1 +1 @@ -90 +50 \ No newline at end of file diff --git a/src/main.py b/main.py similarity index 58% rename from src/main.py rename to main.py index 64a2bd9..83144fe 100644 --- a/src/main.py +++ b/main.py @@ -1,6 +1,9 @@ import os import time import psutil +import tkinter as tk +from tkinter import messagebox +import random # Utility functions def initialize_assets(assets_dir, xp_file, level_file, session_log, total_time_file, questions_file): @@ -43,19 +46,15 @@ def kill_steam(): if proc.name() == "steam.exe": proc.kill() -def show_timer(minutes, questions_file, session_log): - print(f"The session will last {minutes} minutes.") - # Simulate timer and questions - time.sleep(minutes * 60) - with open(session_log, 'a') as f: - f.write(f"Session duration: {minutes} minutes\n") - -def add_xp(xp_file, level_file, session_log): +def update_xp(xp_file, level_file, session_log, correct): with open(xp_file, 'r') as f: xp = int(f.read().strip()) with open(level_file, 'r') as f: level = int(f.read().strip()) - new_xp = xp + 10 + if correct: + new_xp = xp + 10 + else: + new_xp = max(0, xp - 5) # Ensure XP doesn't go below 0 if new_xp >= level * 100: level += 1 new_xp -= (level - 1) * 100 @@ -67,6 +66,59 @@ def add_xp(xp_file, level_file, session_log): with open(session_log, 'a') as f: f.write(f"XP and level updated: {new_xp} XP, Level {level}\n") +def show_timer(minutes, questions_file, session_log): + def update_timer(): + nonlocal seconds_left + if seconds_left > 0: + seconds_left -= 1 + hours, remainder = divmod(seconds_left, 3600) + minutes, seconds = divmod(remainder, 60) + timer_label.config(text=f"Time left: {hours:02}:{minutes:02}:{seconds:02}") + root.after(1000, update_timer) + else: + messagebox.showinfo("Time's up!", "The session has ended.") + with open(session_log, 'a') as f: + f.write(f"Session duration: {minutes} minutes\n") + root.destroy() + + def check_answer(): + 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) + else: + messagebox.showinfo("Incorrect", "You selected the wrong answer.") + update_xp(XP_FILE, LEVEL_FILE, SESSION_LOG, correct=False) + + root = tk.Tk() + root.title("RHEL Learning Timer") + + seconds_left = minutes * 60 + + timer_label = tk.Label(root, text=f"Time left: {minutes:02}:00:00", font=("Helvetica", 16)) + timer_label.pack(pady=20) + + with open(questions_file, 'r') as f: + questions = f.readlines() + + question = random.choice(questions).strip() + question_text, *answers, correct_answer = question.split('|') + + question_label = tk.Label(root, text=f"Question: {question_text}", font=("Helvetica", 14)) + question_label.pack(pady=10) + + answer_var = tk.StringVar(value="") + + 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') + + submit_button = tk.Button(root, text="Submit", command=check_answer, font=("Helvetica", 12)) + submit_button.pack(pady=10) + + root.after(1000, update_timer) + root.mainloop() + # Constants SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) ASSETS_DIR = os.path.join(SCRIPT_DIR, 'assets') @@ -95,9 +147,6 @@ def main(): print("Starting RHEL Learning Session...") show_timer(TIMER_MINUTES, QUESTIONS_FILE, SESSION_LOG) - # Add XP - add_xp(XP_FILE, LEVEL_FILE, SESSION_LOG) - # Log session end log_session(SESSION_LOG, "end") diff --git a/src/utils/session.py b/session.py similarity index 100% rename from src/utils/session.py rename to session.py diff --git a/src/utils/steam.py b/steam.py similarity index 100% rename from src/utils/steam.py rename to steam.py diff --git a/src/utils/timer.py b/timer.py similarity index 100% rename from src/utils/timer.py rename to timer.py diff --git a/src/utils/xp.py b/xp.py similarity index 100% rename from src/utils/xp.py rename to xp.py