python
This commit is contained in:
50
README.md
50
README.md
@@ -1,6 +1,29 @@
|
||||
# RHEL Learning Script
|
||||
|
||||
Welcome to the **RHEL Learning Script**! This script is designed to help you stay focused on your RHEL learning goals by tracking your progress, preventing distractions, and reinforcing key concepts with questions related to RHEL administration.
|
||||
This project provides a script to manage RHEL learning sessions, including a timer, random questions, and XP tracking.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```filetree
|
||||
rhel_learning
|
||||
├── src
|
||||
│ ├── main.py
|
||||
│ ├── assets
|
||||
│ │ ├── xp.txt
|
||||
│ │ ├── level.txt
|
||||
│ │ ├── session.log
|
||||
│ │ ├── questions.txt
|
||||
│ │ └── total_time.txt
|
||||
│ ├── utils
|
||||
│ │ ├── __init__.py
|
||||
│ │ ├── assets.py
|
||||
│ │ ├── session.py
|
||||
│ │ ├── steam.py
|
||||
│ │ ├── timer.py
|
||||
│ │ └── xp.py
|
||||
├── requirements.txt
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
@@ -21,3 +44,28 @@ Ensure you have the following installed on your system:
|
||||
- **wmctrl** (for keeping the browser on top)
|
||||
```bash
|
||||
sudo apt install wmctrl
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
1. Ensure all necessary files are in place.
|
||||
2. Install the required dependencies:
|
||||
|
||||
```sh
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Run the main script:
|
||||
|
||||
```sh
|
||||
python src/main.py
|
||||
```
|
||||
|
||||
## Files
|
||||
|
||||
- `main.py`: Entry point for the application.
|
||||
- `assets.py`: Handles asset initialization and display.
|
||||
- `session.py`: Handles session logging.
|
||||
- `steam.py`: Handles killing Steam processes.
|
||||
- `timer.py`: Handles the timer and asking questions.
|
||||
- `xp.py`: Handles XP and level-up system.
|
||||
|
||||
@@ -34,3 +34,6 @@ 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
|
||||
|
||||
@@ -1 +1 @@
|
||||
180
|
||||
200
|
||||
|
||||
@@ -1 +1 @@
|
||||
80
|
||||
90
|
||||
|
||||
0
requirements.txt
Normal file
0
requirements.txt
Normal file
@@ -138,4 +138,3 @@ kill $STEAM_KILL_PID
|
||||
|
||||
# Log session end
|
||||
log_session "end"
|
||||
|
||||
|
||||
64
rhel_learning/README.md
Normal file
64
rhel_learning/README.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# rhel_learning/rhel_learning/README.md
|
||||
|
||||
# RHEL Learning Project
|
||||
|
||||
This project is a Python-based learning tool designed to help users enhance their knowledge of Red Hat Enterprise Linux (RHEL). It includes a session management system, XP tracking, and a question-and-answer format to facilitate learning.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
rhel_learning
|
||||
├── src
|
||||
│ ├── main.py # Entry point of the application
|
||||
│ ├── assets
|
||||
│ │ ├── xp.txt # Tracks XP earned during sessions
|
||||
│ │ ├── level.txt # Tracks the current level of the user
|
||||
│ │ ├── session.log # Logs session start and end times
|
||||
│ │ ├── questions.txt # Contains questions for learning sessions
|
||||
│ │ └── total_time.txt # Tracks total session time
|
||||
│ ├── utils
|
||||
│ │ ├── __init__.py # Marks the utils directory as a package
|
||||
│ │ ├── assets.py # Functions for managing asset files
|
||||
│ │ ├── session.py # Functions for logging sessions
|
||||
│ │ ├── steam.py # Functions for managing Steam processes
|
||||
│ │ ├── timer.py # Functions for running the session timer
|
||||
│ │ └── xp.py # Functions for managing XP and level-ups
|
||||
├── requirements.txt # Lists dependencies for the project
|
||||
└── README.md # Documentation for the project
|
||||
```
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
1. Clone the repository:
|
||||
```
|
||||
git clone <repository-url>
|
||||
cd rhel_learning
|
||||
```
|
||||
|
||||
2. Install the required dependencies:
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Ensure that the `assets` directory contains the necessary files:
|
||||
- `questions.txt`: Contains the questions for the learning sessions.
|
||||
- `xp.txt`: Initialized to 0 if not present.
|
||||
- `level.txt`: Initialized to 1 if not present.
|
||||
- `total_time.txt`: Initialized to 0 if not present.
|
||||
|
||||
## Usage
|
||||
|
||||
To start the learning session, run the following command:
|
||||
```
|
||||
python src/main.py
|
||||
```
|
||||
|
||||
This will initialize the assets, log the session start, display the session summary, start the timer, and manage the XP and level-up system.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License. See the LICENSE file for more details.
|
||||
4
rhel_learning/requirements.txt
Normal file
4
rhel_learning/requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Flask==2.0.1
|
||||
psutil==5.8.0
|
||||
wmctrl==0.1.0
|
||||
PyQt5==5.15.4
|
||||
105
src/main.py
Normal file
105
src/main.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import os
|
||||
import time
|
||||
import psutil
|
||||
|
||||
# Utility functions
|
||||
def initialize_assets(assets_dir, xp_file, level_file, session_log, total_time_file, questions_file):
|
||||
if not os.path.exists(assets_dir):
|
||||
os.makedirs(assets_dir)
|
||||
if not os.path.exists(xp_file):
|
||||
with open(xp_file, 'w') as f:
|
||||
f.write('0')
|
||||
if not os.path.exists(level_file):
|
||||
with open(level_file, 'w') as f:
|
||||
f.write('1')
|
||||
if not os.path.exists(session_log):
|
||||
open(session_log, 'w').close()
|
||||
if not os.path.exists(total_time_file):
|
||||
with open(total_time_file, 'w') as f:
|
||||
f.write('0')
|
||||
if not os.path.exists(questions_file):
|
||||
raise FileNotFoundError(f"Questions file not found: {questions_file}")
|
||||
|
||||
def log_session(session_log, status):
|
||||
with open(session_log, 'a') as f:
|
||||
f.write(f"Session {status}: {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
|
||||
|
||||
def display_summary(total_time_file, xp_file, level_file):
|
||||
with open(total_time_file, 'r') as f:
|
||||
total_time = int(f.read().strip())
|
||||
with open(xp_file, 'r') as f:
|
||||
xp = int(f.read().strip())
|
||||
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()
|
||||
|
||||
def kill_steam():
|
||||
for proc in psutil.process_iter():
|
||||
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):
|
||||
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 new_xp >= level * 100:
|
||||
level += 1
|
||||
new_xp -= (level - 1) * 100
|
||||
print(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")
|
||||
|
||||
# Constants
|
||||
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
ASSETS_DIR = os.path.join(SCRIPT_DIR, 'assets')
|
||||
XP_FILE = os.path.join(ASSETS_DIR, 'xp.txt')
|
||||
LEVEL_FILE = os.path.join(ASSETS_DIR, 'level.txt')
|
||||
SESSION_LOG = os.path.join(ASSETS_DIR, 'session.log')
|
||||
QUESTIONS_FILE = os.path.join(ASSETS_DIR, 'questions.txt')
|
||||
TOTAL_TIME_FILE = os.path.join(ASSETS_DIR, 'total_time.txt')
|
||||
URL = "https://rol.redhat.com"
|
||||
TIMER_MINUTES = 20
|
||||
|
||||
def main():
|
||||
# Initialize assets
|
||||
initialize_assets(ASSETS_DIR, XP_FILE, LEVEL_FILE, SESSION_LOG, TOTAL_TIME_FILE, QUESTIONS_FILE)
|
||||
|
||||
# Log session start
|
||||
log_session(SESSION_LOG, "start")
|
||||
|
||||
# Display session summary
|
||||
display_summary(TOTAL_TIME_FILE, XP_FILE, LEVEL_FILE)
|
||||
|
||||
# Start killing Steam processes in the background
|
||||
kill_steam()
|
||||
|
||||
# Start session
|
||||
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")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
BIN
src/utils/__pycache__/assets.cpython-312.pyc
Normal file
BIN
src/utils/__pycache__/assets.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/utils/__pycache__/session.cpython-312.pyc
Normal file
BIN
src/utils/__pycache__/session.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/utils/__pycache__/steam.cpython-312.pyc
Normal file
BIN
src/utils/__pycache__/steam.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/utils/__pycache__/timer.cpython-312.pyc
Normal file
BIN
src/utils/__pycache__/timer.cpython-312.pyc
Normal file
Binary file not shown.
BIN
src/utils/__pycache__/xp.cpython-312.pyc
Normal file
BIN
src/utils/__pycache__/xp.cpython-312.pyc
Normal file
Binary file not shown.
44
src/utils/assets.py
Normal file
44
src/utils/assets.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
|
||||
def initialize_assets(assets_dir, xp_file, level_file, session_log, total_time_file, questions_file):
|
||||
if not os.path.isdir(assets_dir):
|
||||
print(f"Assets directory not found: {assets_dir}")
|
||||
print("Please create the 'assets' folder and include the required files:")
|
||||
print("- questions.txt: Contains the questions")
|
||||
print("- xp.txt (optional): Tracks XP, default 0")
|
||||
print("- level.txt (optional): Tracks Level, default 1")
|
||||
print("- total_time.txt (optional): Tracks total session time, default 0")
|
||||
exit(1)
|
||||
|
||||
# Check required files
|
||||
if not os.path.isfile(xp_file):
|
||||
with open(xp_file, 'w') as f:
|
||||
f.write("0")
|
||||
if not os.path.isfile(level_file):
|
||||
with open(level_file, 'w') as f:
|
||||
f.write("1")
|
||||
if not os.path.isfile(session_log):
|
||||
open(session_log, 'w').close()
|
||||
if not os.path.isfile(total_time_file):
|
||||
with open(total_time_file, 'w') as f:
|
||||
f.write("0")
|
||||
if not os.path.isfile(questions_file):
|
||||
print(f"Questions file not found: {questions_file}")
|
||||
print("Please create 'questions.txt' in the 'assets' folder.")
|
||||
exit(1)
|
||||
print(f"Assets initialized in {assets_dir}")
|
||||
|
||||
def display_summary(total_time_file, xp_file, level_file):
|
||||
with open(total_time_file, 'r') as f:
|
||||
total_time = int(f.read().strip())
|
||||
with open(xp_file, 'r') as f:
|
||||
xp = int(f.read().strip())
|
||||
with open(level_file, 'r') as f:
|
||||
level = int(f.read().strip())
|
||||
hours = total_time // 60
|
||||
minutes = total_time % 60
|
||||
print("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()
|
||||
9
src/utils/session.py
Normal file
9
src/utils/session.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from datetime import datetime
|
||||
|
||||
def log_session(session_log, action):
|
||||
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
with open(session_log, 'a') as f:
|
||||
if action == "start":
|
||||
f.write(f"Session started: {timestamp}\n")
|
||||
elif action == "end":
|
||||
f.write(f"Session ended: {timestamp}, Duration: 20 minutes\n")
|
||||
15
src/utils/steam.py
Normal file
15
src/utils/steam.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
def kill_steam():
|
||||
while True:
|
||||
steam_pids = subprocess.check_output("ps aux | grep steam | grep -v grep | awk '{print $2}'", shell=True).decode().strip().split()
|
||||
if steam_pids:
|
||||
print("Killing Steam processes...")
|
||||
for pid in steam_pids:
|
||||
try:
|
||||
os.kill(int(pid), 9)
|
||||
except Exception as e:
|
||||
print(f"Failed to kill Steam process {pid}: {e}")
|
||||
time.sleep(5) # Check every 5 seconds
|
||||
28
src/utils/timer.py
Normal file
28
src/utils/timer.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import time
|
||||
import random
|
||||
|
||||
def show_timer(timer_minutes, questions_file, session_log):
|
||||
seconds = timer_minutes * 60
|
||||
for i in range(1, seconds + 1):
|
||||
print(f"Time remaining: {seconds - i} seconds", end='\r')
|
||||
time.sleep(1)
|
||||
print("\nSession complete!")
|
||||
ask_random_question(questions_file, session_log)
|
||||
|
||||
def ask_random_question(questions_file, session_log):
|
||||
with open(questions_file, 'r') as f:
|
||||
questions = f.readlines()
|
||||
random_question = random.choice(questions).strip().split('|')
|
||||
question, opt1, opt2, opt3, correct = random_question
|
||||
print(question)
|
||||
print(f"1. {opt1}")
|
||||
print(f"2. {opt2}")
|
||||
print(f"3. {opt3}")
|
||||
answer = input("Choose an answer (1-3): ")
|
||||
with open(session_log, 'a') as f:
|
||||
if answer == correct:
|
||||
print("Correct answer!")
|
||||
f.write(f"{question}|Correct\n")
|
||||
else:
|
||||
print(f"Wrong answer. The correct option was: {correct}")
|
||||
f.write(f"{question}|Wrong\n")
|
||||
16
src/utils/xp.py
Normal file
16
src/utils/xp.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def add_xp(xp_file, level_file, session_log):
|
||||
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 new_xp >= level * 100:
|
||||
level += 1
|
||||
print(f"LEVEL UP! You are now Level {level}!")
|
||||
new_xp -= (level - 1) * 100
|
||||
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")
|
||||
Reference in New Issue
Block a user