forked from Mahesh0253/Media-Search-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
one_time_indexer.py
46 lines (37 loc) · 1.32 KB
/
one_time_indexer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import logging
import logging.config
# Get logging configurations
logging.config.fileConfig('logging.conf')
logging.getLogger().setLevel(logging.ERROR)
import asyncio
from pyrogram import Client
from info import SESSION, USER_SESSION, API_ID, API_HASH, BOT_TOKEN, CHANNELS
from utils import save_file
async def main():
"""Save old files in database with the help of user bot"""
user_bot = Client(USER_SESSION, API_ID, API_HASH)
bot = Client(SESSION, API_ID, API_HASH, bot_token=BOT_TOKEN)
await user_bot.start()
await bot.start()
try:
for channel in CHANNELS:
async for user_message in user_bot.iter_history(channel):
message = await bot.get_messages(
channel,
user_message.message_id,
replies=0,
)
for file_type in ("document", "video", "audio"):
media = getattr(message, file_type, None)
if media is not None:
break
else:
continue
media.file_type = file_type
media.caption = message.caption
await save_file(media)
finally:
await user_bot.stop()
await bot.stop()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())