【问题标题】:No sending duplicates不发送重复项
【发布时间】:2022-11-21 04:25:35
【问题描述】:

我正在尝试制作我的第一个电报机器人。他的任务很简单:它从 ebay 上抓取最后发布的项目,并通过电报向我发送更新。
我想用电报工作来做到这一点:

context.job_queue.run_repeating(items_call, context=chat_id, name=str(chat_id), interval=6)

其中 items_call 是每 6 秒调用一次 ebay 爬虫的函数

我面临的问题是:我想让我的机器人记住他已经在聊天中发送的项目,我不知道该怎么做,有没有特定的功能?

我正在使用 python-telegram-bot 库

如有帮助,谢谢

enter image description here

我想要一些建议或帮助...谢谢

【问题讨论】:

  • 请将您的代码直接复制并粘贴到您的问题中,而不是使用图像。

标签: python telegram python-telegram-bot


【解决方案1】:

给你一套。

在您的代码中的某个时刻,您想要声明该集合:

sent_jobs = set()

然后,在您的项目调用函数中,您需要使用该集合:

def items_call:
    # ... Code you already had here
    for its in items:
        if its in sent_jobs:   # Check if the item has been sent before
            continue
        else:
            # ... Do code you had previously
            sent_jobs.add(its) # Add the item to the set

【讨论】:

    猜你喜欢
    • 2019-07-18
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多