0

So I'm trying to send SMS texts that are being pulled from a list via Twilio to phone numbers. I'm able to to send certain indexed values from the list by specifying the index in the code manually. However, my plan is to run this everyday at a set time via Windows Task Scheduler and perhaps by converting the Python Script to an .exe program. My question is: How am I able to increment the list by one every time the program is ran? Here is My code:

    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()
mansmokes
  • 15
  • 2

1 Answers1

0

Twilio developer evangelist here.

In order to store and increment a value that points to a position in the list you will need to save it somewhere outside of the script so that it can exist across different instances of the script running. You could do this by writing the pointer to a file that you read at the start of the script, and increment and write back to the file at the end of the script.

For example, you could store the pointer in a file called pointer.txt and add code to read it at the start of your script and write it at the end like this:

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))
philnash
  • 70,667
  • 10
  • 60
  • 88