Home | Trees | Indices | Help |
|
---|
|
A module that provides convenience functions for sending alerts. Currently this includes sending text (SMS) messages or emails.
This is accomplished through two mechanisms: Google Voice or SMTP.
To use Google Voice, this module requires a Google Voice account and depends on pygooglevoice to access your Google Voice account.
You can sign up for a Google Voice account at voice.google.com.
pygooglevoice is in PyPI but unfortunately is not configured properly. You'll have to download the source and run:
sudo python2 setup.py install
in the directory containing setup.py. You can download pygooglevoice at code.google.com/p/pygooglevoice.
A quick example of sending an SMS message with Google Voice:
import nflgame.alert nflgame.alert.google_voice_login('YOUR GMAIL ADDRESS', 'YOUR PASSWORD') nflgame.alert.sms('1112223333', 'This is a text message!')
If you don't have a Google Voice account or don't want to install a
third party library, you can still use this module but the
google_voice_login
function will not work.
The disadvantage of using Google Voice is that it limits text messages. Since you'll probably be using this module to send a fair number of alerts, this might be prohibitive.
SMTP can be used to send SMS messages or emails. For sending SMS messages, the SMTP approach requires that you know the provider of the recipient's cell phone (i.e., Verizon, Sprint, T-Mobile). Although this is a burden, sending SMS messages through email doesn't seem to be as vigorously rate limited as Google Voice is.
To send an SMS message using your GMail account:
import nflgame.alert nflgame.alert.gmail_login('YOUR GMAIL ADDRESS', 'YOUR PASSWORD') nflgame.alert.sms('1112223333', 'Test message', provider='Verizon')
In this case, the provider
parameter is required.
Similarly, you can send email alerts with your GMail account:
import nflgame.alert nflgame.alert.gmail_login('YOUR GMAIL ADDRESS', 'YOUR PASSWORD') nflgame.alert.email('somewhere@someplace.com', 'Email message')
Once you login to GMail using gmail_login
, you may send
both text messages and emails. You may be logged into Google Voice and
GMail at the same time.
You may use SMTP servers that aren't GMail by using
smtp_login
. In fact, gmail_login
is a
special case of smtp_login
:
def gmail_login(email, passwd): def connect(): gmail = smtplib.SMTP('smtp.gmail.com', port=587) gmail.starttls() return gmail smtp_login(email, passwd, connect)
The connection setup must be provided as a function because it will typically need to be reused in a long running program. (i.e., If you don't send an alert for a while, you'll probably be disconnected from the SMTP server. In which case, the connection setup will be executed again.)
Functions | |||
|
|||
|
|||
|
|||
|
|||
|
Variables | |
providers =
A dictionary of providers. |
|
__package__ =
|
Function Details |
Logs into your Google Voice account with your full email address (i.e., 'something@gmail.com') and password. This MUST be called before using send without the provider parameter. login only needs to be called once per program execution. Note that your Google Voice login information is probably the same as your gmail login information. Please be careful with your login credentials! (It is not a bad idea to setup an entirely separate Google Voice account just for sending SMS.) |
Logs into an SMTP mail server. connectfun should be a function that takes no parameters and returns an smtplib.SMTP instance that is ready to be logged into. (See the source of gmail_login for an example.) username and passwd are then used to log into that smtplib.SMTP instance. connectfun may be called again automatically if the SMTP connection is broken during program execution. |
Logs into your GMail account with your full email address (i.e., 'something@gmail.com') and password. gmail_login MUST be called before using sms with the provider parameter. It only needs to be called once per program execution. |
Sends an email to to_email with a message containing msg. from_email is an optional parameter that specifies the 'from' email address. If gmail_login was used, this is automatically populated using the login email address. Otherwise it is left empty. |
Sends an SMS message to phone_number (which should be a string) with a message containing msg. If you're using Google Voice to send SMS messages, google_voice_login MUST be called before sms can be called. google_voice_login only needs to be called once per program execution. The provider parameter can be used to send SMS messages via email. It is necessary because SMS messages are sent by sending a message to an email like '111222333@vtext.com' or '1112223333@txt.att.net'. Thus, each phone number must be paired with a provider. A provider can be specified either as a carrier name (i.e., 'Verizon' or 'ATT'), or as simply the domain (i.e., 'vtext.com' or 'txt.att.net'). Supported providers are in the module level providers variable. Please feel free to add to it and submit a pull request. The provider parameter is not currently used, but is anticipated if this module provides a way to send SMS messages via emails. A provider will be required to look up the email domain. (i.e., for Verizon it's 'vtext.com'.) Note that these are SMS messages, and each SMS message is limited to 160 characters. If msg is longer than that and you're using Google Voice, it will be broken up into multiple SMS messages (hopefully). Otherwise, if you're sending SMS messages via email, the behavior will vary depending upon your carrier. |
Variables Details |
providersA dictionary of providers. The keys are English name identifiers of a SMS provider. The values are domain suffixes that come after the '@' symbol in an email address.
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Sep 18 18:09:30 2012 | http://epydoc.sourceforge.net |