Skip to content

Commit e953a8f

Browse files
REFACTOR: Updating the 'Main Template' Python Project
1 parent d12cf3e commit e953a8f

4 files changed

Lines changed: 3 additions & 471 deletions

File tree

Main Template/.env-example

Lines changed: 0 additions & 2 deletions
This file was deleted.

Main Template/main.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@
5151
import os # For running a command in the terminal
5252
import platform # For getting the operating system name
5353
import sys # For system-specific parameters and functions
54-
import telegram_bot as telegram_module # For setting Telegram prefix and device info
5554
from colorama import Style # For coloring the terminal
5655
from Logger import Logger # For logging output to both terminal and file
5756
from pathlib import Path # For handling file paths
58-
from telegram_bot import TelegramBot, send_telegram_message # For sending progress messages to Telegram
5957

6058

6159
# Macros:
@@ -72,9 +70,6 @@ class BackgroundColors: # Colors for the terminal
7270
# Execution Constants:
7371
VERBOSE = False # Set to True to output verbose messages
7472

75-
# Telegram Bot Setup:
76-
TELEGRAM_BOT = None # Global Telegram bot instance (initialized in setup_telegram_bot)
77-
7873
# Logger Setup:
7974
logger = Logger(f"./Logs/{Path(__file__).stem}.log", clean=True) # Create a Logger instance
8075
sys.stdout = logger # Redirect stdout to the logger
@@ -136,36 +131,12 @@ def verify_dot_env_file():
136131
env_path = Path(__file__).parent / ".env" # Path to the .env file
137132

138133
if not verify_filepath_exists(env_path): # If the .env file does not exist
139-
print(f"{BackgroundColors.CYAN}.env{BackgroundColors.YELLOW} file not found at {BackgroundColors.CYAN}{env_path}{BackgroundColors.YELLOW}. Telegram messages may not be sent.{Style.RESET_ALL}")
134+
print(f"{BackgroundColors.CYAN}.env{BackgroundColors.YELLOW} file not found at {BackgroundColors.CYAN}{env_path}{BackgroundColors.YELLOW}.{Style.RESET_ALL}")
140135
return False # Return False
141136

142137
return True # Return True if the .env file exists
143138

144139

145-
def setup_telegram_bot():
146-
"""
147-
Sets up the Telegram bot for progress messages.
148-
149-
:return: None
150-
"""
151-
152-
verbose_output(
153-
f"{BackgroundColors.GREEN}Setting up Telegram bot for messages...{Style.RESET_ALL}"
154-
) # Output the verbose message
155-
156-
verify_dot_env_file() # Verify if the .env file exists
157-
158-
global TELEGRAM_BOT # Declare the module-global telegram_bot variable
159-
160-
try: # Try to initialize the Telegram bot
161-
TELEGRAM_BOT = TelegramBot() # Initialize Telegram bot for progress messages
162-
telegram_module.TELEGRAM_DEVICE_INFO = f"{telegram_module.get_local_ip()} - {platform.system()}"
163-
telegram_module.RUNNING_CODE = os.path.basename(__file__)
164-
except Exception as e:
165-
print(f"{BackgroundColors.RED}Failed to initialize Telegram bot: {e}{Style.RESET_ALL}")
166-
TELEGRAM_BOT = None # Set to None if initialization fails
167-
168-
169140
def to_seconds(obj):
170141
"""
171142
Converts various time-like objects to seconds.
@@ -282,8 +253,8 @@ def main():
282253
end="\n\n",
283254
) # Output the welcome message
284255
start_time = datetime.datetime.now() # Get the start time of the program
285-
286-
send_telegram_message(TELEGRAM_BOT, [f"Starting the Main Template Python program at {start_time.strftime('%d/%m/%Y - %H:%M:%S')}"]) # Send start message to Telegram
256+
257+
# Implement logic here
287258

288259
finish_time = datetime.datetime.now() # Get the finish time of the program
289260
print(
@@ -292,9 +263,6 @@ def main():
292263
print(
293264
f"\n{BackgroundColors.BOLD}{BackgroundColors.GREEN}Program finished.{Style.RESET_ALL}"
294265
) # Output the end of the program message
295-
296-
send_telegram_message(TELEGRAM_BOT, [f"Finished the Main Template Python program at {finish_time.strftime('%d/%m/%Y - %H:%M:%S')} with execution time {calculate_execution_time(start_time, finish_time)}"]) # Send finish message to Telegram
297-
298266
(
299267
atexit.register(play_sound) if RUN_FUNCTIONS["Play Sound"] else None
300268
) # Register the play_sound function to be called when the program finishes

Main Template/requirements.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
anyio==4.12.1
2-
certifi==2026.1.4
31
colorama==0.4.6
4-
h11==0.16.0
5-
httpcore==1.0.9
6-
httpx==0.28.1
7-
idna==3.11
8-
python-dotenv==1.2.1
9-
python-telegram-bot==22.6
10-
typing_extensions==4.15.0

0 commit comments

Comments
 (0)