简体   繁体   English

制作无限循环热图

[英]make infinite loop pyrogram

I need this part of script work infinitely(send messages), but it works only one time and then stops我需要这部分脚本无限工作(发送消息),但它只工作一次然后停止

f = open('text.txt')
t = 1
with app:
    while True:
        for line in f.readlines():
            try:
                app.send_message(chat_id=line[13:].rstrip(), text=txt)
                print(f"Успешно написал в чат по ссылке {line}")
                time.sleep(0.5)
            except:
                print(f"Что-то пошло не так... Возможно в чате {line} включен медленный режим")```
            

The for loop stops when it gets to the end of the file. for循环在到达文件末尾时停止。 When the while loop repeats, there's nothing for the for loop to read because you're already at the end of the file.while循环重复时, for循环不会读取任何内容,因为您已经在文件的末尾。

You can seek to the beginning each time.每次都可以从头开始。

f = open('text.txt')
t = 1
with app:
    while True:
        f.seek(0)
        for line in f.readlines():
            try:
                app.send_message(chat_id=line[13:].rstrip(), text=txt)
                print(f"Успешно написал в чат по ссылке {line}")
                time.sleep(0.5)
            except:
                print(f"Что-то пошло не так... Возможно в чате {line} включен медленный режим")     

Or you could save the contents to a list and loop through that.或者您可以将内容保存到列表中并循环播放。

with open('text.txt') as f:
    lines = f.readlines()
t = 1
with app:
    while True:
        for line in lines:
            try:
                app.send_message(chat_id=line[13:].rstrip(), text=txt)
                print(f"Успешно написал в чат по ссылке {line}")
                time.sleep(0.5)
            except:
                print(f"Что-то пошло не так... Возможно в чате {line} включен медленный режим")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM