I wrote a simple python script to text people cat facts once an hour. It works fine throughout the day, but it keeps crashing with connection refused errors through out the night. It's only like 10-20 people, so I don't think I'm getting blocked for over-usage. Here's my code:
import smtplib
import time
import urllib
server = smtplib.SMTP('smtp.gmail.com:587')
print 'Connection Good'
server.starttls()
print 'ttls Started'
server.login('catfacts452@gmail.com','xxxxxxxxxx')
print 'OAuth Good'
while True:
try:
z = urllib.urlopen('http://catfacts-api.appspot.com/api/facts?number=1')
except:
continue
html = z.read()
print '\nOpened'
j = html.replace('{"facts": ["', '')
word = j.replace('"], "success": "true"}','')
print 'Formatted'
try:
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@vtext.com','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@txt.att.net','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@tmomail.net','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@tmomail.net','Cat Facts!\n' + word)
#server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@txt.att.net','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@vtext.com','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@vtext.com','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@messaging.sprintpcs.com','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@messaging.sprintpcs.com','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@txt.att.net','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@vtext.com','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@vtext.com','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@messaging.sprintpcs.com','Cat Facts!\n' + word)
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx@txt.att.net','Cat Facts!\n' + word)
print 'Message Outbound @' + time.strftime("%H:%M:%S")
timeint = time.strftime("%H:%M:%S")
timetry = timeint[:2]
if int(timetry) > 06 and int(timetry) < 22:
server.sendmail('catfacts452@gmail.com','xxxxxxxxxx','success @ ' + time.strftime("%H:%M:%S") )
except:
break
time.sleep(3600)