gpt4 book ai didi

Setting the DATETIME filter gives me a flood problem(设置DateTime筛选器会出现泛洪问题)

转载 作者:bug小助手 更新时间:2023-10-25 14:49:47 29 4
gpt4 key购买 nike



With this code I can print message ID and filenames into results.txt and I have not flood problems. Only problem is that it doesn't print strings between 27-28 august 2023 but it prints all strings.

使用此代码,我可以将消息ID和文件名打印到Results.txt中,并且不会出现泛洪问题。唯一的问题是,它不会打印2023年8月27-28日之间的字符串,但会打印所有字符串。


import time
from pyrogram import Client
from datetime import datetime, timedelta

app = Client(
name="@Peter_LongX",
api_id=*******,
api_hash="b**********************",
phone_number="+3*****",
password="" or None
)

group_id = -1001867911973
topic_id = 664
msg_file_dict = {}

start_date = datetime(2023, 8, 27)
end_date = datetime(2023, 8, 28)


async def main():
async with app:
processed_messages = 0 # Initialize the counter
async for message in app.get_discussion_replies(chat_id=group_id, message_id=topic_id):
print(f"Message ID: {message.id}")
message_date = message.date

if start_date <= message_date <= end_date: # Check if the message date is within the specified range
print(f"Message ID: {message.id}")

file_name = None # Declare the variable outside the if statement

if message.video or (message.document and (message.document.mime_type.endswith("rar") or message.document.mime_type.endswith("zip") or message.document.mime_type.endswith("pdf") or message.document.mime_type.endswith("epub") or message.document.mime_type.endswith("cbr"))):
file = message.video or message.document
print("Video or rar/zip/pdf/epub/cbr file found")

msg_id = message.id
file_name = file.file_name or f"VID_{message.id}_{file.file_unique_id}.{file.mime_type.split('/')[-1]}"
print(file_name)
msg_file_dict[msg_id] = file_name
print()

# Appending results to the text file with utf-8 encoding
with open("results.txt", "a", encoding="utf-8") as file:
if file_name:
file.write(f"Message ID: {message.id}\n")
file.write(f"File Name: {file_name}\n")
file.write("\n")

processed_messages += 1 # Increment the counter

if processed_messages % 40 == 0:
time.sleep(15) # Pause for 15 seconds after every 40 messages

app.run(main())

So, I thought I'd modify the code a bit so that I can only print strings that are between Aug 27-28. Indeed, in this way, I print strings within those dates.. but, unlike before, now the terminal gives me a FLOOD problem. I don't understand why if I didn't get this error before

所以,我想我应该稍微修改一下代码,这样我就只能打印8月27日至28日之间的字符串。事实上,通过这种方式,我会在这些日期内打印字符串。但是,与以前不同的是,现在航站楼给我带来了洪水问题。我不明白为什么如果我以前没有得到这个错误


[previous code]


async def main():
async with app:
processed_messages = 0 # Initialize the counter
async for message in app.get_discussion_replies(chat_id=group_id, message_id=topic_id):
message_date = message.date

if start_date <= message_date <= end_date: # Check if the message date is within the specified range
print(f"Message ID: {message.id}")

file_name = None # Initialize the variable

if message.video or (message.document and (message.document.mime_type.endswith("rar") or message.document.mime_type.endswith("zip") or message.document.mime_type.endswith("pdf") or message.document.mime_type.endswith("epub") or message.document.mime_type.endswith("cbr"))):
file = message.video or message.document
print("Video or rar/zip/pdf/epub/cbr file found")

msg_id = message.id
file_name = file.file_name or f"VID_{message.id}_{file.file_unique_id}.{file.mime_type.split('/')[-1]}"
print(file_name)
msg_file_dict[msg_id] = file_name

# Appending results to the text file with utf-8 encoding
with open("results.txt", "a", encoding="utf-8") as file:
file.write(f"Message ID: {msg_id}\n")
file.write(f"File Name: {file_name}\n")
file.write("\n")

processed_messages += 1 # Increment the counter

if processed_messages % 40 == 0:
time.sleep(15) # Pause for 15 seconds after every 40 messages

app.run(main())

The error in second code is this

第二个代码中的错误是


    raise getattr(
pyrogram.errors.exceptions.flood_420.FloodWait: Telegram says: [420 FLOOD_WAIT_X] - A wait of 15 seconds is required (caused by "messages.GetReplies")

Please look at the difference between the 2 behaviors, I don't understand why introducing dates as a filter now gives me a flood error when it didn't before.
HERE here you can see the difference between running the first code vs the second code
In my opinion, but I could be wrong, perhaps it is necessary to implement some code to manage the logic of the datetime intervals because if the logic of the simple listing does not give me flood problems because introducing datetime filter then there is something that produces the flood error

请看看这两种行为的不同之处,我不明白为什么现在引入日期作为过滤器会给我带来泛洪错误,而以前没有。在这里,您可以看到运行第一个代码和运行第二个代码之间的差异,我认为这可能是错误的,也许有必要实现一些代码来管理日期时间间隔的逻辑,因为如果简单清单的逻辑没有给我带来泛洪问题,因为引入了日期时间过滤器,那么就有一些东西会产生泛洪错误


更多回答
优秀答案推荐

Floodwait happens because you retreive mesages without a sleep. the if condition you used for checking date of the messages prevents the sleep to be executed.

洪水等待的发生是因为你在不睡觉的情况下检索消息。您用于检查消息日期的IF条件阻止执行休眠。


the solution:

解决方案:


you should put this part of code outside of if condition:

您应该将这部分代码放在if条件之外:


processed_messages += 1  # Increment the counter

if processed_messages % 40 == 0:
time.sleep(15) # Pause for 15 seconds after every 40 messages

also put a condition to check if messages are older than 27 august and break the loop. you don't need to go further when you reached 26 august.

还设置了一个条件来检查消息是否早于8月27日,并中断循环。当你到了8月26日的时候,你不需要再走得更远了。


so the updated code will be:

因此,更新后的代码将为:


async def main():
async with app:
processed_messages = 0 # Initialize the counter
async for message in app.get_discussion_replies(chat_id=group_id, message_id=topic_id):
message_date = message.date

if start_date <= message_date <= end_date: # Check if the message date is within the specified range
print(f"Message ID: {message.id}")

file_name = None # Initialize the variable

if message.video or (message.document and (message.document.mime_type.endswith("rar") or message.document.mime_type.endswith("zip") or message.document.mime_type.endswith("pdf") or message.document.mime_type.endswith("epub") or message.document.mime_type.endswith("cbr"))):
file = message.video or message.document
print("Video or rar/zip/pdf/epub/cbr file found")

msg_id = message.id
file_name = file.file_name or f"VID_{message.id}_{file.file_unique_id}.{file.mime_type.split('/')[-1]}"
print(file_name)
msg_file_dict[msg_id] = file_name

# Appending results to the text file with utf-8 encoding
with open("results.txt", "a", encoding="utf-8") as file:
file.write(f"Message ID: {msg_id}\n")
file.write(f"File Name: {file_name}\n")
file.write("\n")

elif message_date <= start_date:
break

processed_messages += 1 # Increment the counter

if processed_messages % 40 == 0:
time.sleep(15) # Pause for 15 seconds after every 40 messages

app.run(main())

更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com