refactor: update formatting

This commit is contained in:
Eugene Evstafev 2025-04-18 14:25:24 +01:00
parent ff0f42626b
commit eca9fb48cf
2 changed files with 622 additions and 463 deletions

773
main.py

File diff suppressed because it is too large Load diff

View file

@ -40,9 +40,13 @@ except ValueError:
print("\n----- Telegram Session String Generator -----\n") print("\n----- Telegram Session String Generator -----\n")
print("This script will generate a session string for your Telegram account.") print("This script will generate a session string for your Telegram account.")
print("You will be asked to enter your phone number and the verification code sent to your Telegram app.") print(
"You will be asked to enter your phone number and the verification code sent to your Telegram app."
)
print("The generated session string can be added to your .env file.") print("The generated session string can be added to your .env file.")
print("\nYour credentials will NOT be stored on any server and are only used for local authentication.\n") print(
"\nYour credentials will NOT be stored on any server and are only used for local authentication.\n"
)
try: try:
# Connect to Telegram and generate the session string # Connect to Telegram and generate the session string
@ -58,17 +62,19 @@ try:
print("\nIMPORTANT: Keep this string private and never share it with anyone!") print("\nIMPORTANT: Keep this string private and never share it with anyone!")
# Optional: auto-update the .env file # Optional: auto-update the .env file
choice = input("\nWould you like to automatically update your .env file with this session string? (y/N): ") choice = input(
if choice.lower() == 'y': "\nWould you like to automatically update your .env file with this session string? (y/N): "
)
if choice.lower() == "y":
try: try:
# Read the current .env file # Read the current .env file
with open('.env', 'r') as file: with open(".env", "r") as file:
env_contents = file.readlines() env_contents = file.readlines()
# Update or add the SESSION_STRING line # Update or add the SESSION_STRING line
session_string_line_found = False session_string_line_found = False
for i, line in enumerate(env_contents): for i, line in enumerate(env_contents):
if line.startswith('TELEGRAM_SESSION_STRING='): if line.startswith("TELEGRAM_SESSION_STRING="):
env_contents[i] = f"TELEGRAM_SESSION_STRING={session_string}\n" env_contents[i] = f"TELEGRAM_SESSION_STRING={session_string}\n"
session_string_line_found = True session_string_line_found = True
break break
@ -77,7 +83,7 @@ try:
env_contents.append(f"TELEGRAM_SESSION_STRING={session_string}\n") env_contents.append(f"TELEGRAM_SESSION_STRING={session_string}\n")
# Write back to the .env file # Write back to the .env file
with open('.env', 'w') as file: with open(".env", "w") as file:
file.writelines(env_contents) file.writelines(env_contents)
print("\n.env file updated successfully!") print("\n.env file updated successfully!")