安排 Twilio 命令以递增方式从列表中发送索引项

Schedule a Twilio command to send indexed items from list incrementally

所以我正在尝试将通过 Twilio 从列表中提取的 SMS 文本发送到 phone 号码。我可以通过在代码中手动指定索引来发送列表中的某些索引值。但是,我的计划是每天在设定的时间通过 Windows 任务计划程序 运行 执行此操作,或许还可以将 Python 脚本转换为 .exe 程序。我的问题是:每次程序 运行 时,我如何能够将列表递增 1?这是我的代码:

    COURSE_QUOTES = ['Day 17: I see no neutral things.',
                 'Day 18: I am not alone in experiencing the effects of my seeing.',
                 'Day 19: I am not alone in experiencing the effects of my thoughts.',
                 'Day 20: I am determined to see.',
                 'Day 21: I am determined to see things differently.',
                 'Day 22: What I see is a form of vengeance.',
                 'Day 23: I can escape from the world I see by giving up attack thoughts.',
                 'Day 24: I do not perceive my own best interests.',
                 'Day: 25: I do not know what anything is for.' ]



numbers = ['1111111111', '2222222222', '3333333333']




def send_message(quote_list = COURSE_QUOTES):
    account = ("account number")
    token = ("tokenID")
    client = Client(account, token)

    client.messages.create(from_='444-444-4444',
                           to= numbers,
                           body=COURSE_QUOTES[0]
                                              )

send_message()

这里是 Twilio 开发人员布道者。

为了存储和递增指向列表中某个位置的值,您需要将其保存在脚本之外的某个位置,以便它可以存在于脚本的不同实例中 运行。您可以通过将指针写入您在脚本开头读取的文件,并在脚本末尾递增并写回文件来完成此操作。

例如,您可以将指针存储在一个名为 pointer.txt 的文件中,然后添加代码以在脚本的开头读取它并在末尾写入,如下所示:

with open('./pointer.txt', 'r') as reader:
    pointer = int(reader.read())

COURSE_QUOTES = ['Day 17: I see no neutral things.',
                 'Day 18: I am not alone in experiencing the effects of my seeing.',
                 'Day 19: I am not alone in experiencing the effects of my thoughts.',
                 'Day 20: I am determined to see.',
                 'Day 21: I am determined to see things differently.',
                 'Day 22: What I see is a form of vengeance.',
                 'Day 23: I can escape from the world I see by giving up attack thoughts.',
                 'Day 24: I do not perceive my own best interests.',
                 'Day: 25: I do not know what anything is for.' ]

numbers = ['1111111111', '2222222222', '3333333333']

def send_message(quote):
    account = ("account number")
    token = ("tokenID")
    client = Client(account, token)

    client.messages.create(from_='444-444-4444',
                           to= numbers,
                           body=quote)

send_message(COURSE_QUOTES[pointer])

pointer += 1
with open('./pointer.txt', 'w') as writer:
    writer.write(str(pointer))