Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Session String Generator for Telegram Multi-Part File Streamer | |
| Generates Pyrogram session strings for multi-session load balancing | |
| """ | |
| import asyncio | |
| import sys | |
| from pyrogram import Client | |
| async def generate_session_string(): | |
| """Generate a Pyrogram session string""" | |
| print("=" * 60) | |
| print("Telegram Session String Generator") | |
| print("=" * 60) | |
| print() | |
| # Get credentials | |
| try: | |
| api_id = input("Enter your API_ID: ").strip() | |
| if not api_id: | |
| print("β API_ID is required!") | |
| return | |
| api_id = int(api_id) | |
| api_hash = input("Enter your API_HASH: ").strip() | |
| if not api_hash: | |
| print("β API_HASH is required!") | |
| return | |
| print() | |
| print("π Credentials validated!") | |
| print() | |
| print("π± You will now receive a code on your Telegram app.") | |
| print(" Please enter the code when prompted.") | |
| print() | |
| except ValueError: | |
| print("β Invalid API_ID! Must be a number.") | |
| return | |
| except KeyboardInterrupt: | |
| print("\n\nβ Cancelled by user.") | |
| return | |
| # Create client | |
| client = Client( | |
| name="session_generator", | |
| api_id=api_id, | |
| api_hash=api_hash, | |
| in_memory=True | |
| ) | |
| try: | |
| # Start client (will prompt for phone number and code) | |
| await client.start() | |
| # Get session string | |
| session_string = await client.export_session_string() | |
| # Get user info | |
| me = await client.get_me() | |
| print() | |
| print("=" * 60) | |
| print("β Session String Generated Successfully!") | |
| print("=" * 60) | |
| print() | |
| print(f"π€ Account: {me.first_name} {me.last_name or ''}") | |
| print(f"π Phone: +{me.phone_number}") | |
| print(f"π Username: @{me.username or 'N/A'}") | |
| print() | |
| print("π Session String:") | |
| print("-" * 60) | |
| print(session_string) | |
| print("-" * 60) | |
| print() | |
| print("β οΈ IMPORTANT:") | |
| print(" 1. Keep this session string PRIVATE and SECURE") | |
| print(" 2. Anyone with this string can access your account") | |
| print(" 3. Add this to SESSION_STRINGS in your .env file") | |
| print(" 4. You can generate multiple session strings for") | |
| print(" load balancing (comma-separated)") | |
| print() | |
| print("π‘ Example .env configuration:") | |
| print("-" * 60) | |
| print(f"SESSION_STRINGS={session_string},YOUR_SECOND_SESSION_STRING") | |
| print("-" * 60) | |
| print() | |
| # Stop client | |
| await client.stop() | |
| except Exception as e: | |
| print(f"\nβ Error: {str(e)}") | |
| if "PASSWORD" in str(e).upper(): | |
| print("\nβ οΈ Your account has 2FA enabled.") | |
| print(" Please enter your password when prompted.") | |
| return | |
| finally: | |
| if client.is_connected: | |
| await client.stop() | |
| def main(): | |
| """Main function""" | |
| try: | |
| asyncio.run(generate_session_string()) | |
| except KeyboardInterrupt: | |
| print("\n\nβ Cancelled by user.") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |