Welcome, guest | Sign In | My Account | Store | Cart

This is a little class I banged together so I could have my app send me alerts on my cell phone. This could work for any provider but the only way to figure out what fields it wants is to go to the messaging page and search throught the source. Have fun with this, this class could be made really cool if it worked for all the major providers.

Python, 63 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Written by Sam Hendley
# Class to send SMS text message to ATT phones
import urllib
import string
"""This class allows you to send SMS messages to any ATT wireless phone
I built this by going to the ATT text send site and searching the source
to find out exactly what fields it needs, there is a 110 character limit"""
class ATTAlerter:
    def __init__(self,number,subject,whofrom):
        """number must be a string of format 'xxx-xxx-xxxx'"""
        self.number = number
        self.subject = self.toHtml(subject)
        self.whofrom = self.toHtml(whofrom)
    def SendMessage(self, message):
        """Message is string to send to user"""
        self.message = self.toHtml(message)
        num = len(self.message)+len(self.whofrom)+len(self.subject)
        if num > 110:
            return 2
        astring = 'http://www.mobile.att.net/messagecenter/pagersend.cgi?pin="'
        astring = astring + self.number
        astring = astring + '"&from="'
        astring = astring + self.whofrom
        astring = astring + '"&subject="'
        astring = astring + self.subject
        astring = astring + '"&message="'
        astring = astring + self.message
        astring = astring + '"&size="'
        astring = astring + str(num)+'"'
        #print astring
        
        myUrlclass = urllib.FancyURLopener()
        try:
            webPage = myUrlclass.open(astring)
            #print webPage
        except IOError:
            print 'webaddress failed'
            return -1
        #while 1:
        data = webPage.read(8192)
        if data:
            #print str(data)
            if string.find(str(data),"<TITLE>400 Bad Request</TITLE>") != -1:
                return 4
        else:
            return 3
        
        webPage.close()
        return 0
    def toHtml(self,str):
        str = string.replace(str, ' ','%20')
        #print str
        return str


######################################################################
######    Test function  replace ###-###-#### wiht your number
######################################

alerter = ATTAlerter.ATTAlerter('###-###-####','Test Message','Python Script')
alerter.SendMessage('This message came from python!!')

###############################################################

Cool Huh?

3 comments

hal-aspn 18 years, 8 months ago  # | flag

Example code doesn't execute. The example code doesn't execute -- there is no method

ATTAlerter

in the class.

The correct line should be:

alerter = ATTAlerter('###-###-####','Test Message','Python Script')

Even cooler when it works. :)

Sam Hendley (author) 18 years, 8 months ago  # | flag

True that... Sorry I tested it with a seperate module, pasted the code in from there.

Tim Gerla 18 years, 5 months ago  # | flag

Email acccess to SMS. You can also send a simple email to ##########@mobile.att.net for the same effect.