0

我在 Heroku 上部署了带有 pyTelegramBotAPI 的烧瓶电报机器人。需要在开始消息中获得新的列表长度。在gettinglist.py中每 5 分钟刷新一次列表。找不到我的错误,请帮忙。

僵尸软件

import config
import gettinglist
from gettinglist import getting_list
import telebot
from flask import Flask, request
from threading import Thread

def app_run():
    app.run(host="0.0.0.0", port=os.environ.get('PORT', 80))

msg_start = """
Lenght of list now: %d
""" % config.LIST_LENGHT

application_thread = Thread(target=app_run)
getting_list_thread = Thread(target=getting_list)

bot = telebot.TeleBot("<MY_BOT_TOKEN>")

@bot.message_handler(commands=['start'])
def start():
    cid = m.chat.id
    bot.send_message(cid, msg_start, parse_mode='html')

@app.route("/bot", methods=['POST'])
def getMessage():
    bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
    return "ok", 200

@app.route("/")
def webhook():
    bot.remove_webhook()
    bot.set_webhook(url="<HEROKU_APP_URL>")
    return "ok", 200

if __name__ == '__main__':
    application_thread.start()
    getting_list_thread.start()

获取列表.py

import config
from time import sleep

LIST_LENGHT = 0
LIST = []

def getting_list():
    while True:
        global LIST
        global LIST_LENGHT

        LIST = [num for num in range(0, 100)]
        config.LIST_LENGHT = len(LIST)

        return LIST
        sleep(300)

配置文件

LIST_LENGHT = 0
4

0 回答 0