107 lines
3.5 KiB
Python
107 lines
3.5 KiB
Python
|
|
import asyncio
|
|
import json
|
|
import logging
|
|
import os
|
|
|
|
import aiosqlite
|
|
from dotenv import load_dotenv
|
|
from pyrogram import Client
|
|
|
|
from steam_parser.steam import SteamLogin
|
|
from utils.strings import parse_post
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
handlers=[
|
|
logging.FileHandler("steam_guard.log", encoding='utf-8'),
|
|
logging.StreamHandler()
|
|
]
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
load_dotenv()
|
|
|
|
API_ID = os.getenv('API_ID')
|
|
API_HASH = os.getenv('API_HASH')
|
|
CHANNEL_URL = os.getenv('CHANNEL_URL')
|
|
|
|
|
|
async def fetch_and_monitor_accounts():
|
|
client = Client(
|
|
name='pyrogram_session',
|
|
api_id=API_ID,
|
|
api_hash=API_HASH
|
|
)
|
|
|
|
channel_name = os.path.basename(CHANNEL_URL)
|
|
|
|
await client.start()
|
|
|
|
processed_messages = set() # Хранение ID обработанных сообщений
|
|
|
|
while True:
|
|
accounts = []
|
|
async for message in client.get_chat_history(channel_name, limit=200):
|
|
text = message.text or message.caption
|
|
if text and message.id not in processed_messages:
|
|
pairs = parse_post(text)
|
|
for login, password in pairs:
|
|
accounts.append({
|
|
'username': login,
|
|
'password': password,
|
|
'date': message.date.isoformat()
|
|
})
|
|
processed_messages.add(message.id)
|
|
|
|
if accounts:
|
|
# Сортируем по дате (от новых к старым)
|
|
accounts.sort(key=lambda x: x['date'], reverse=True)
|
|
top_50 = accounts[:50]
|
|
|
|
async with aiosqlite.connect('credentials.db') as db:
|
|
# Создаем таблицу, если её нет
|
|
await db.execute('''
|
|
CREATE TABLE IF NOT EXISTS accounts (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
username TEXT NOT NULL,
|
|
password TEXT NOT NULL,
|
|
date TEXT NOT NULL,
|
|
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
''')
|
|
|
|
await db.execute('''
|
|
CREATE TABLE IF NOT EXISTS backup_accounts (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
username TEXT NOT NULL,
|
|
password TEXT NOT NULL,
|
|
date TEXT NOT NULL,
|
|
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
''')
|
|
|
|
# Очищаем старые записи перед добавлением новых
|
|
await db.execute('DELETE FROM accounts')
|
|
|
|
# Вставляем новые записи
|
|
for account in top_50:
|
|
await db.execute(
|
|
'INSERT INTO accounts (username, password, date) VALUES (?, ?, ?)',
|
|
(account['username'], account['password'], account['date'])
|
|
)
|
|
|
|
await db.commit()
|
|
|
|
logger.info(f"\n✅ Сохранено {len(top_50)} аккаунтов в credentials.json")
|
|
|
|
await SteamLogin().open_steam_login_page_and_type()
|
|
|
|
await asyncio.sleep(30)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(fetch_and_monitor_accounts())
|
|
# asyncio.run(SteamLogin().open_steam_login_page_and_type()) |