0

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)
  • you can give sendmail a list of recipients. And you can use the datetime-module to get the current hour. – Daniel Apr 24 '14 at 10:43
  • Sounds like a system issue, not a programming issue. You might have better luck with sites like ServerFault or Unix&Linux. – jrennie Apr 24 '14 at 11:26
  • luckily i already have a linux setup. i guess ill try that, but im gonna leave this question open for a bit to see any other ideas. – user3568398 Apr 24 '14 at 11:30

0 Answers0