from pyrogram import Client from pyrogram.raw.functions.contacts import Search from pyrogram.errors import FloodWait, PeerIdInvalid, UsernameNotOccupied import time # Укажи свой api_id и api_hash api_id = АПИ ИД api_hash = "АПИХЕШ" def main(): chats = set() # Загрузка поисковых запросов with open('queries.txt', encoding='utf-8') as file: queries = [q.strip() for q in file if q.strip()] with Client("session", api_id, api_hash) as client: for query in queries: try: result = client.invoke(Search(q=query, limit=100)) except FloodWait as e: print(f"FloodWait: спим {e.value} секунд") time.sleep(e.value) continue except Exception as e: print(f"Ошибка при поиске {query}: {e}") continue for chat in result.chats: username = chat.username # Если это канал без username, попробуем взять его у привязанного чата if not username and not chat.megagroup and not chat.gigagroup: try: full_chat = client.get_chat(chat.id) linked_chat = getattr(full_chat, "linked_chat", None) if linked_chat and linked_chat.username: username = linked_chat.username except (PeerIdInvalid, UsernameNotOccupied, Exception): continue if username: print(f"[{query}] — @{username}") chats.add(username) # Чтение уже сохранённых чатов try: with open('result_chats.txt', 'r', encoding='utf-8') as file: existing = set(line.strip() for line in file if line.strip()) except FileNotFoundError: existing = set() # Запись новых new_chats = chats - existing if new_chats: with open('result_chats.txt', 'a', encoding='utf-8') as file: for chat in sorted(new_chats): file.write(f"{chat}\n") if name == "main": try: main() except (KeyboardInterrupt, SystemExit): print("Прервано пользователем.") Python from pyrogram import Client from pyrogram.raw.functions.contacts import Search from pyrogram.errors import FloodWait, PeerIdInvalid, UsernameNotOccupied import time # Укажи свой api_id и api_hash api_id = АПИ ИД api_hash = "АПИХЕШ" def main(): chats = set() # Загрузка поисковых запросов with open('queries.txt', encoding='utf-8') as file: queries = [q.strip() for q in file if q.strip()] with Client("session", api_id, api_hash) as client: for query in queries: try: result = client.invoke(Search(q=query, limit=100)) except FloodWait as e: print(f"FloodWait: спим {e.value} секунд") time.sleep(e.value) continue except Exception as e: print(f"Ошибка при поиске {query}: {e}") continue for chat in result.chats: username = chat.username # Если это канал без username, попробуем взять его у привязанного чата if not username and not chat.megagroup and not chat.gigagroup: try: full_chat = client.get_chat(chat.id) linked_chat = getattr(full_chat, "linked_chat", None) if linked_chat and linked_chat.username: username = linked_chat.username except (PeerIdInvalid, UsernameNotOccupied, Exception): continue if username: print(f"[{query}] — @{username}") chats.add(username) # Чтение уже сохранённых чатов try: with open('result_chats.txt', 'r', encoding='utf-8') as file: existing = set(line.strip() for line in file if line.strip()) except FileNotFoundError: existing = set() # Запись новых new_chats = chats - existing if new_chats: with open('result_chats.txt', 'a', encoding='utf-8') as file: for chat in sorted(new_chats): file.write(f"{chat}\n") if name == "main": try: main() except (KeyboardInterrupt, SystemExit): print("Прервано пользователем.") вписываю, не реагирует, раньше просило скачать pyrogram и tgcrypto, скачал и перестал работать
from pyrogram import Client from pyrogram.raw.functions.contacts import Search from pyrogram.errors import FloodWait, PeerIdInvalid, UsernameNotOccupied import time # Укажи свой api_id и api_hash api_id = YOUR_API_ID api_hash = "YOUR_API_HASH" async def main(): chats = set() # Загрузка поисковых запросов with open('queries.txt', encoding='utf-8') as file: queries = [q.strip() for q in file if q.strip()] async with Client("session", api_id, api_hash) as client: for query in queries: try: result = await client.invoke(Search(q=query, limit=100)) except FloodWait as e: print(f"FloodWait: спим {e.value} секунд") time.sleep(e.value) continue except Exception as e: print(f"Ошибка при поиске {query}: {e}") continue for chat in result.chats: username = chat.username # Если это канал без username, попробуем взять его у привязанного чата if not username and not chat.megagroup and not chat.gigagroup: try: full_chat = await client.get_chat(chat.id) linked_chat = getattr(full_chat, "linked_chat", None) if linked_chat and linked_chat.username: username = linked_chat.username except (PeerIdInvalid, UsernameNotOccupied, Exception): continue if username: print(f"[{query}] — @{username}") chats.add(username) # Чтение уже сохранённых чатов try: with open('result_chats.txt', 'r', encoding='utf-8') as file: existing = set(line.strip() for line in file if line.strip()) except FileNotFoundError: existing = set() # Запись новых new_chats = chats - existing if new_chats: with open('result_chats.txt', 'a', encoding='utf-8') as file: for chat in sorted(new_chats): file.write(f"{chat}\n") if __name__ == "__main__": import asyncio try: asyncio.run(main()) except (KeyboardInterrupt, SystemExit): print("Прервано пользователем.") Python from pyrogram import Client from pyrogram.raw.functions.contacts import Search from pyrogram.errors import FloodWait, PeerIdInvalid, UsernameNotOccupied import time # Укажи свой api_id и api_hash api_id = YOUR_API_ID api_hash = "YOUR_API_HASH" async def main(): chats = set() # Загрузка поисковых запросов with open('queries.txt', encoding='utf-8') as file: queries = [q.strip() for q in file if q.strip()] async with Client("session", api_id, api_hash) as client: for query in queries: try: result = await client.invoke(Search(q=query, limit=100)) except FloodWait as e: print(f"FloodWait: спим {e.value} секунд") time.sleep(e.value) continue except Exception as e: print(f"Ошибка при поиске {query}: {e}") continue for chat in result.chats: username = chat.username # Если это канал без username, попробуем взять его у привязанного чата if not username and not chat.megagroup and not chat.gigagroup: try: full_chat = await client.get_chat(chat.id) linked_chat = getattr(full_chat, "linked_chat", None) if linked_chat and linked_chat.username: username = linked_chat.username except (PeerIdInvalid, UsernameNotOccupied, Exception): continue if username: print(f"[{query}] — @{username}") chats.add(username) # Чтение уже сохранённых чатов try: with open('result_chats.txt', 'r', encoding='utf-8') as file: existing = set(line.strip() for line in file if line.strip()) except FileNotFoundError: existing = set() # Запись новых new_chats = chats - existing if new_chats: with open('result_chats.txt', 'a', encoding='utf-8') as file: for chat in sorted(new_chats): file.write(f"{chat}\n") if __name__ == "__main__": import asyncio try: asyncio.run(main()) except (KeyboardInterrupt, SystemExit): print("Прервано пользователем.") Попробуй
h3artkrush, там бы была ошибка о том что нет переменной main, скорее всего у него __ не вставилось просто
Trump, from pyrogram import Client from pyrogram.raw.functions.contacts import Search from pyrogram.errors import FloodWait, PeerIdInvalid, UsernameNotOccupied import time api_id = АПИ_ИД api_hash = "АПИХЕШ" def main(): print("Запуск программы...") chats = set() try: with open('queries.txt', encoding='utf-8') as file: queries = [q.strip() for q in file if q.strip()] print(f"Загружено {len(queries)} запросов") except FileNotFoundError: print("ОШИБКА: файл queries.txt не найден!") return if not queries: print("ОШИБКА: список запросов пуст!") return print("Подключение к Telegram...") with Client("session", api_id, api_hash) as client: print("Подключение успешно!") for i, query in enumerate(queries, 1): print(f"Обработка запроса {i}/{len(queries)}: '{query}'") max_retries = 3 retry_count = 0 while retry_count < max_retries: try: result = client.invoke(Search(q=query, limit=100)) break except FloodWait as e: print(f"FloodWait для запроса '{query}': спим {e.value} секунд") time.sleep(e.value) retry_count += 1 except Exception as e: print(f"Ошибка при поиске '{query}': {e}") break else: print(f"Превышено количество попыток для запроса '{query}'") continue if 'result' not in locals(): continue found_chats = 0 for chat in result.chats: username = chat.username if not username and not chat.megagroup and not chat.gigagroup: try: full_chat = client.get_chat(chat.id) linked_chat = getattr(full_chat, "linked_chat", None) if linked_chat and linked_chat.username: username = linked_chat.username except (PeerIdInvalid, UsernameNotOccupied, Exception): continue if username: print(f"[{query}] — @{username}") chats.add(username) found_chats += 1 print(f"Найдено {found_chats} чатов для запроса '{query}'") time.sleep(1) try: with open('result_chats.txt', 'r', encoding='utf-8') as file: existing = set(line.strip() for line in file if line.strip()) except FileNotFoundError: existing = set() new_chats = chats - existing if new_chats: with open('result_chats.txt', 'a', encoding='utf-8') as file: for chat in sorted(new_chats): file.write(f"{chat}\n") print(f"Добавлено {len(new_chats)} новых чатов") else: print("Новых чатов не найдено") print(f"Всего уникальных чатов: {len(chats)}") if __name__ == "__main__": try: main() except (KeyboardInterrupt, SystemExit): print("Прервано пользователем.") except Exception as e: print(f"Неожиданная ошибка: {e}") Python from pyrogram import Client from pyrogram.raw.functions.contacts import Search from pyrogram.errors import FloodWait, PeerIdInvalid, UsernameNotOccupied import time api_id = АПИ_ИД api_hash = "АПИХЕШ" def main(): print("Запуск программы...") chats = set() try: with open('queries.txt', encoding='utf-8') as file: queries = [q.strip() for q in file if q.strip()] print(f"Загружено {len(queries)} запросов") except FileNotFoundError: print("ОШИБКА: файл queries.txt не найден!") return if not queries: print("ОШИБКА: список запросов пуст!") return print("Подключение к Telegram...") with Client("session", api_id, api_hash) as client: print("Подключение успешно!") for i, query in enumerate(queries, 1): print(f"Обработка запроса {i}/{len(queries)}: '{query}'") max_retries = 3 retry_count = 0 while retry_count < max_retries: try: result = client.invoke(Search(q=query, limit=100)) break except FloodWait as e: print(f"FloodWait для запроса '{query}': спим {e.value} секунд") time.sleep(e.value) retry_count += 1 except Exception as e: print(f"Ошибка при поиске '{query}': {e}") break else: print(f"Превышено количество попыток для запроса '{query}'") continue if 'result' not in locals(): continue found_chats = 0 for chat in result.chats: username = chat.username if not username and not chat.megagroup and not chat.gigagroup: try: full_chat = client.get_chat(chat.id) linked_chat = getattr(full_chat, "linked_chat", None) if linked_chat and linked_chat.username: username = linked_chat.username except (PeerIdInvalid, UsernameNotOccupied, Exception): continue if username: print(f"[{query}] — @{username}") chats.add(username) found_chats += 1 print(f"Найдено {found_chats} чатов для запроса '{query}'") time.sleep(1) try: with open('result_chats.txt', 'r', encoding='utf-8') as file: existing = set(line.strip() for line in file if line.strip()) except FileNotFoundError: existing = set() new_chats = chats - existing if new_chats: with open('result_chats.txt', 'a', encoding='utf-8') as file: for chat in sorted(new_chats): file.write(f"{chat}\n") print(f"Добавлено {len(new_chats)} новых чатов") else: print("Новых чатов не найдено") print(f"Всего уникальных чатов: {len(chats)}") if __name__ == "__main__": try: main() except (KeyboardInterrupt, SystemExit): print("Прервано пользователем.") except Exception as e: print(f"Неожиданная ошибка: {e}") попробуй