I have a simple Python program that repeats the following process at 30 second intervals: uses the Gmail API to check my inbox, looks for a certain kind of mail, and if it is found, uses the Twilio API to call me.
I've been running this program on my machine, but I'd like for it to be running 24x7. A friend said I should be able to do this using Heroku. I'm unable to figure out how to do this and would appreciate any help. I set up Heroku, and first tried deploying my script (which I've reproduced below) and got errors reproduced at the end of post.
I also tried running it within a Flask app function, but the code only ran once when I opened the Heroku link, and I wasn't able to get it to continue running in the background.
Please let me know if I should be doing this differently/using a different hosting/platform provider.
#Procfile
web: python gmail_twilio.py
#Logs error
2016-07-13T03:35:39.635528+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pacific-woodland-28065.herokuapp.com request_id=54912af8-83a6-4feb-bb36-def791621e5f fwd="171.50.142.162" dyno= connect= service= status=503 bytes=
#gmail_twilio.py
while True:
inbox_list = ListMessagesMatchingQuery(service, '##', query="in:inbox -label:called ")# create list with non called labels
if len(inbox_list)>0:
twiliocall() # function to call me
for element in inbox_list:
ModifyMessage(service, 'me', element[u'id'], {'removeLabelIds': [], 'addLabelIds': ['Label_3']}) # add called label
time.sleep(30) # wait for 30 seconds