From 303ca0090df1f03380ee434f7315dab9dfae1621 Mon Sep 17 00:00:00 2001 From: alexpolo1 Date: Tue, 7 Jan 2025 21:51:09 +0100 Subject: [PATCH] python --- README.md | 50 ++++++++- assets/session.log | 3 + assets/total_time.txt | 2 +- assets/xp.txt | 2 +- requirements.txt | 0 rhel_learning.sh | 1 - rhel_learning/README.md | 64 +++++++++++ rhel_learning/requirements.txt | 4 + src/main.py | 105 ++++++++++++++++++ src/utils/__pycache__/assets.cpython-312.pyc | Bin 0 -> 3415 bytes src/utils/__pycache__/session.cpython-312.pyc | Bin 0 -> 820 bytes src/utils/__pycache__/steam.cpython-312.pyc | Bin 0 -> 1109 bytes src/utils/__pycache__/timer.cpython-312.pyc | Bin 0 -> 1937 bytes src/utils/__pycache__/xp.cpython-312.pyc | Bin 0 -> 1567 bytes src/utils/assets.py | 44 ++++++++ src/utils/session.py | 9 ++ src/utils/steam.py | 15 +++ src/utils/timer.py | 28 +++++ src/utils/xp.py | 16 +++ 19 files changed, 339 insertions(+), 4 deletions(-) create mode 100644 requirements.txt create mode 100644 rhel_learning/README.md create mode 100644 rhel_learning/requirements.txt create mode 100644 src/main.py create mode 100644 src/utils/__pycache__/assets.cpython-312.pyc create mode 100644 src/utils/__pycache__/session.cpython-312.pyc create mode 100644 src/utils/__pycache__/steam.cpython-312.pyc create mode 100644 src/utils/__pycache__/timer.cpython-312.pyc create mode 100644 src/utils/__pycache__/xp.cpython-312.pyc create mode 100644 src/utils/assets.py create mode 100644 src/utils/session.py create mode 100644 src/utils/steam.py create mode 100644 src/utils/timer.py create mode 100644 src/utils/xp.py diff --git a/README.md b/README.md index 9ad82c6..8eb649e 100644 --- a/README.md +++ b/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. diff --git a/assets/session.log b/assets/session.log index b47b887..e912d80 100644 --- a/assets/session.log +++ b/assets/session.log @@ -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 diff --git a/assets/total_time.txt b/assets/total_time.txt index 3af99ee..08839f6 100644 --- a/assets/total_time.txt +++ b/assets/total_time.txt @@ -1 +1 @@ -180 +200 diff --git a/assets/xp.txt b/assets/xp.txt index d15a2cc..d61f00d 100644 --- a/assets/xp.txt +++ b/assets/xp.txt @@ -1 +1 @@ -80 +90 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/rhel_learning.sh b/rhel_learning.sh index 4af3002..6c48df7 100755 --- a/rhel_learning.sh +++ b/rhel_learning.sh @@ -138,4 +138,3 @@ kill $STEAM_KILL_PID # Log session end log_session "end" - diff --git a/rhel_learning/README.md b/rhel_learning/README.md new file mode 100644 index 0000000..823ec06 --- /dev/null +++ b/rhel_learning/README.md @@ -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 + 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. \ No newline at end of file diff --git a/rhel_learning/requirements.txt b/rhel_learning/requirements.txt new file mode 100644 index 0000000..b12c7ba --- /dev/null +++ b/rhel_learning/requirements.txt @@ -0,0 +1,4 @@ +Flask==2.0.1 +psutil==5.8.0 +wmctrl==0.1.0 +PyQt5==5.15.4 \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..64a2bd9 --- /dev/null +++ b/src/main.py @@ -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() diff --git a/src/utils/__pycache__/assets.cpython-312.pyc b/src/utils/__pycache__/assets.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..107726137969d18d1a602449f885af1834f371a5 GIT binary patch literal 3415 zcmcguO-vg{6rT0&+Ur055(qyDnP3NF0vK9FBs58j0yqamNgAn1dO((Ufu)Pr?5qp8 zM#-U-K%xq?2OLFFe5A@H$6lMJ${~k3@>Y$uR#mA{rQFg|2?_PknYDLqh>4=A=~|wB z^WOL7{mkrp^VsWk0sK7va%t*sI{?3tiTT)y#8x9FHUJNJN&?paZ~F{fqj(yRwnZw) zJSVWRDAu+fLeu!a^$Q+1fNBY5%rz|z05fdaq)4W~J*q&Wan)hUc`5~NgF7};Mu9R} zWiDM2%T(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VNz&Zy&BVJR2-P8&p0xl z-tWI3{N{AlHLNisn7{mfdN|#mb@?>LPo|^kx-^q@9nqLpJpDYp-Gse10^8YUuuq2D z2H9>nwS#;(6<>4=(e$^@j-hJ$0oyUuLO-P0A&=u>H9OSkc-X=Y`5i%8;V{zZBt{Cq v23vRzj3n=HXJ%zSAqnS{4$LDZ1Cb4UK~ogoCpq literal 0 HcmV?d00001 diff --git a/src/utils/__pycache__/session.cpython-312.pyc b/src/utils/__pycache__/session.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0485ae24f8f0ad1ca138a226e8b4c7a2ab88d0f4 GIT binary patch literal 820 zcmZ`%&ubGw6n>N4O|wl>6HTj#;-Z8$VBJP(kywO+(AHuvJxJ>zEZu3k?fwWe8`8uC zdhnoLjCzP5LXJu={TDp<60Kqx>dBM0mVkwvoZaqXFTQ2o%zNMazBjzty<~C_xb3}Z zmevr!FE0o!5*&IX{Lls+bYy}BD}X?cJcAWf6LR8juPBFDOxIlO8Wvs+X&w;eOW>>b zhr2eoyv3<)oUICSJ0T_ohclawb^>lQ;tqsBgI{DPP@06M&_KGdIR-#R8p4JgR{h&` zu@QL>y7WN^)ezX1IV zRy`RedzHMkRc2_7id;qE*3YZ!j)hgt#9L~~a8BuA7YKabl4EY)vNPBpJ zMX+G=FGxEtKRmfGB~xE&Q9PBT zjF!VvQpF`Htyq#lhD)e8Y2?Xll4+!*f~BaYVT%#TDo1qWQ` zk&Y*{Yju{!PdMP^UvV$Em62t> z-VJ;gew}oJUQ!L6s=nH#8=C{0!sfzOV2i1RC-#GryTQrdb%w@I&0a$PQ>cH8N87x2 zY=qqo1;(Q6c9bQ0#ADE_ZqOTT&`0G={T>j)M5j0RwBuGzlM5=oZG?$QpNrW|1nCap TA@Cjo-ysMzJRA%eeZ>C<1P1zf literal 0 HcmV?d00001 diff --git a/src/utils/__pycache__/timer.cpython-312.pyc b/src/utils/__pycache__/timer.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000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wvvFP|9< z%0sD9Ii{;}GL@10)my42*I>|s84Jd8t>*{jSdz$^jgO{D%v8xyIp>wn4|cDyJzc!z zPNmhPg%U~Aa_ef0SlBT2MB2h>onbhmCrs5s6r^N6n;yQJ&{WG~3)gM0p&CXal^oVm zaSL9xTv-}z-&#^I8?d0B>9R><q1aQ2l#WcH z_syaALa4xPEUv9`b5Rf<@)P`HRE$n~7lZ&y)V8szz*O)DOPTa62!6&2FxK_T!K%2M z)!qlEBCE9d=FaKXY2mr|h4SL?%Z_=UvLHlRNFS^-SNybfdpflhH*L)By|&UoQ!}&8 zMgz= 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")