mirror of
https://gitverse.ru/kpa39l/chronicle.nixg.ru.git
synced 2026-09-29 09:55:08 +00:00
72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Login script using Pyrogram as fallback when Telethon fails.
|
|
|
|
Pyrogram sometimes works when Telethon is blocked.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Add project root to path
|
|
project_root = Path(__file__).parent
|
|
sys.path.insert(0, str(project_root))
|
|
os.chdir(project_root)
|
|
|
|
from pyrogram import Client
|
|
import asyncio
|
|
import configparser
|
|
|
|
async def login():
|
|
"""Interactive login using Pyrogram."""
|
|
print("\n" + "=" * 60)
|
|
print("TELEGRAM ARCHIVER - PYROGRAM AUTHENTICATION")
|
|
print("=" * 60)
|
|
|
|
# Parse .env manually
|
|
env_vars = {}
|
|
with open('.env', 'r') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if line and not line.startswith('#') and '=' in line:
|
|
key, value = line.split('=', 1)
|
|
env_vars[key.strip()] = value.strip()
|
|
|
|
api_id = int(env_vars.get('API_ID', 0))
|
|
api_hash = env_vars.get('API_HASH', '')
|
|
phone = env_vars.get('PHONE', '')
|
|
|
|
print(f"\nPhone: {phone}")
|
|
print(f"API ID: {api_id}")
|
|
print("=" * 60)
|
|
print("\nTelegram will send you a code via SMS automatically")
|
|
print("if the app code is not available.")
|
|
print("=" * 60)
|
|
|
|
# Create Pyrogram client
|
|
app = Client(
|
|
name="pyrogram-session",
|
|
api_id=api_id,
|
|
api_hash=api_hash,
|
|
phone_number=phone,
|
|
workdir=project_root
|
|
)
|
|
|
|
async with app:
|
|
print("\nSuccessfully logged in!")
|
|
print(f"Session saved to: {project_root / 'pyrogram-session.session'}")
|
|
|
|
# Get me info
|
|
me = await app.get_me()
|
|
print(f"\nLogged in as: {me.first_name} @{me.username}")
|
|
print(f"User ID: {me.id}")
|
|
|
|
if me.username:
|
|
print(f"\nYou can now archive your channel: @{me.username}")
|
|
|
|
print("\n" + "=" * 60)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(login())
|