Добавление задержки 3 мин. на каждые 1000 запросов user_info
parent
fd9d23f2d2
commit
1785e22ea1
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright © 2021-2022 https://t.me/ssleg
|
Copyright © 2021-2025 https://t.me/ssleg
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# Telegram chat reader v1.11
|
# Telegram chat reader v1.20
|
||||||
# 02/02/2022
|
# 07/10/2025
|
||||||
# https://t.me/ssleg © 2021-2022
|
# https://t.me/ssleg © 2021-2025
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -101,7 +101,7 @@ def stat_upload(read_mess):
|
||||||
'Content-Type': 'application/json; charset=utf-8'
|
'Content-Type': 'application/json; charset=utf-8'
|
||||||
}
|
}
|
||||||
# noinspection HttpUrlsUsage
|
# noinspection HttpUrlsUsage
|
||||||
stat_upload_url = 'http://188.124.50.148/stat_up'
|
stat_upload_url = 'https://api.ssleg.tech/v1/stat_up'
|
||||||
finger = str(api_id) + api_hash
|
finger = str(api_id) + api_hash
|
||||||
hash_md5 = md5(finger.encode())
|
hash_md5 = md5(finger.encode())
|
||||||
request_json = {'protocol_version': '1.2', 'application': 'Chat Reader', 'app_version': get_version(),
|
request_json = {'protocol_version': '1.2', 'application': 'Chat Reader', 'app_version': get_version(),
|
||||||
|
@ -387,7 +387,8 @@ def add_private():
|
||||||
async for dialog in client.iter_dialogs():
|
async for dialog in client.iter_dialogs():
|
||||||
entity = dialog.entity
|
entity = dialog.entity
|
||||||
if type(entity) == types.Channel:
|
if type(entity) == types.Channel:
|
||||||
if entity.broadcast is False and entity.username is None and entity.has_link is False:
|
# if entity.broadcast is False and entity.username is None and entity.has_link is False:
|
||||||
|
if entity.broadcast is False and entity.username is None:
|
||||||
count += 1
|
count += 1
|
||||||
print(f'{count}. {entity.title} ({entity.participants_count} человек)')
|
print(f'{count}. {entity.title} ({entity.participants_count} человек)')
|
||||||
chats_dict[count] = (entity.id, entity.title)
|
chats_dict[count] = (entity.id, entity.title)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Chat reader module v1.10
|
# Chat reader module v1.20
|
||||||
# 29/01/2022
|
# 07/10/2025
|
||||||
# https://t.me/ssleg © 2021-2022
|
# https://t.me/ssleg © 2021-2025
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from asyncio import sleep
|
from asyncio import sleep
|
||||||
|
@ -11,6 +11,7 @@ from telethon import TelegramClient, types, errors
|
||||||
|
|
||||||
user_dict = {}
|
user_dict = {}
|
||||||
channel_dict = {}
|
channel_dict = {}
|
||||||
|
get_user_count = 0
|
||||||
|
|
||||||
client: TelegramClient
|
client: TelegramClient
|
||||||
con: extensions.connection
|
con: extensions.connection
|
||||||
|
@ -19,8 +20,17 @@ cursor: extensions.cursor
|
||||||
|
|
||||||
# обновление информации о пользователях
|
# обновление информации о пользователях
|
||||||
async def update_user(user_id):
|
async def update_user(user_id):
|
||||||
|
global get_user_count
|
||||||
|
if get_user_count == 999:
|
||||||
|
levent = 'пауза по лимиту на запрос юзер инфо.'
|
||||||
|
print(levent)
|
||||||
|
logging.info(levent)
|
||||||
|
await sleep(180)
|
||||||
|
get_user_count = 0
|
||||||
|
|
||||||
user_info = await client.get_entity(user_id)
|
user_info = await client.get_entity(user_id)
|
||||||
user_dict[user_id] = 0
|
user_dict[user_id] = 0
|
||||||
|
get_user_count += 1
|
||||||
|
|
||||||
entry = (user_id, user_info.first_name, user_info.last_name, user_info.username, user_info.phone, user_info.bot,
|
entry = (user_id, user_info.first_name, user_info.last_name, user_info.username, user_info.phone, user_info.bot,
|
||||||
user_info.deleted)
|
user_info.deleted)
|
||||||
|
@ -56,6 +66,7 @@ async def update_channel(channel_id):
|
||||||
async def read_messages(chat_id, start_id, limit):
|
async def read_messages(chat_id, start_id, limit):
|
||||||
read_count = 0
|
read_count = 0
|
||||||
last_read_id = 0
|
last_read_id = 0
|
||||||
|
try:
|
||||||
async for message in client.iter_messages(chat_id, reverse=True, limit=limit, min_id=start_id):
|
async for message in client.iter_messages(chat_id, reverse=True, limit=limit, min_id=start_id):
|
||||||
read_count += 1
|
read_count += 1
|
||||||
message_id = message.id
|
message_id = message.id
|
||||||
|
@ -90,7 +101,7 @@ async def read_messages(chat_id, start_id, limit):
|
||||||
reply_top = message.reply_to.reply_to_top_id
|
reply_top = message.reply_to.reply_to_top_id
|
||||||
if message.reply_to.reply_to_peer_id is not None:
|
if message.reply_to.reply_to_peer_id is not None:
|
||||||
levent = f'message_peer: {message.reply_to}, {message_id}'
|
levent = f'message_peer: {message.reply_to}, {message_id}'
|
||||||
print(levent)
|
# print(levent)
|
||||||
logging.warning(levent)
|
logging.warning(levent)
|
||||||
|
|
||||||
fwd_from_user_id = None
|
fwd_from_user_id = None
|
||||||
|
@ -118,15 +129,24 @@ async def read_messages(chat_id, start_id, limit):
|
||||||
|
|
||||||
mess_grouped_id = message.grouped_id
|
mess_grouped_id = message.grouped_id
|
||||||
|
|
||||||
entry = (message_chat_id, message_id, user_id, channel_id, message_date, mess_grouped_id, reply_to, reply_top,
|
entry = (
|
||||||
|
message_chat_id, message_id, user_id, channel_id, message_date, mess_grouped_id, reply_to, reply_top,
|
||||||
fwd_from_channel_id, fwd_from_post, fwd_from_user_id, fwd_from_name, message_text, media_type, action)
|
fwd_from_channel_id, fwd_from_post, fwd_from_user_id, fwd_from_name, message_text, media_type, action)
|
||||||
|
|
||||||
cursor.execute('''insert into chat_reader_mess (chat_id, message_id, user_id, channel_id, message_date,
|
cursor.execute('''insert into chat_reader_mess (chat_id, message_id, user_id, channel_id, message_date,
|
||||||
grouped_id, reply_to, reply_top, fwd_from_channel_id, fwd_from_channel_post, fwd_from_user_id,
|
grouped_id, reply_to, reply_top, fwd_from_channel_id,
|
||||||
|
fwd_from_channel_post, fwd_from_user_id,
|
||||||
fwd_from_name, message_txt, message_media, message_action)
|
fwd_from_name, message_txt, message_media, message_action)
|
||||||
values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)''', entry)
|
values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)''', entry)
|
||||||
|
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
|
except errors.ChannelPrivateError:
|
||||||
|
print('чат стал приватным/удален/аккаунт для чтения забанен.')
|
||||||
|
|
||||||
|
except errors.ChannelInvalidError:
|
||||||
|
print('приватный чат не знаком с другим аккаунтом для чтения.')
|
||||||
|
|
||||||
return read_count, last_read_id
|
return read_count, last_read_id
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
psycopg2~=2.8.6
|
psycopg2~=2.9.9
|
||||||
toml~=0.10.2
|
toml~=0.10.2
|
||||||
Telethon~=1.24.0
|
Telethon~=1.36.0
|
||||||
requests~=2.23.0
|
requests~=2.25.1
|
Loading…
Reference in New Issue