forked from CodeChix-OpenSource/PiDoorbell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_notifications.py
More file actions
82 lines (59 loc) · 2.83 KB
/
send_notifications.py
File metadata and controls
82 lines (59 loc) · 2.83 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# Copyright (C) 2013-2014 Rupa Dachere <rupa@codechix.org>>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Download the twilio-python library from http://twilio.com/docs/libraries
# Use python-twitter to tweet - github.com/bear/python-twitter
import sys
sys.path.append("/home/pi/pycon2013/pidoorbell")
from twilio.rest import TwilioRestClient
import twitter
import optparse
import sms_auth_info
def send_sms(sms_url):
client = TwilioRestClient(sms_auth_info.account_sid, sms_auth_info.auth_token)
print '\n\n ************************ SENDING SMS WITH URL: ', sms_url ," *************************\n\n"
body_url = "PiDoorbell for PyCon 2014! Visitor @FrontDoor: " + sms_url
## to: you cell phone number; from: twilio's assigned number (from "numbers" tab on your acct.)
message = client.sms.messages.create(to="+1XXXYYYZZZZ", from_="+1XXXYYYZZZZ", body=body_url)
def send_tweet(tweet_url):
api = twitter.Api(consumer_key=sms_auth_info.twitter_auth_key, consumer_secret=sms_auth_info.twitter_auth_secret, \
access_token_key=sms_auth_info.twitter_access_key, access_token_secret=sms_auth_info.twitter_access_secret)
api.VerifyCredentials()
print '\n\n ************************ SENDING TWEET WITH URL: ', tweet_url ," *************************\n\n"
post_message = "PiDoorbell for #pycon2014 using GPIO!! Visitor @FrontDoor: " + tweet_url
status = api.PostUpdate(post_message)
#print status
#### MAIN ####
parser = optparse.OptionParser()
parser.add_option('-u', '--sms_url',
action="store", dest="sms_url",
help="sms url string", default="spam")
parser.add_option('-m', '--mode',
action="store", dest="mode",
help="mode: \"sms\" or \"tweet\" or \"all\"", default="spam")
options, args = parser.parse_args()
if options.sms_url == "spam" or options.mode == "spam":
print "**** HEY! You forgot the URL or MODE for the SMS: ***"
print "**** Usage: send_sms -m <sms/tweet/all> -u <URL_string> ***"
sys.exit()
if options.mode == "sms":
send_sms(options.sms_url)
elif options.mode == "tweet":
send_tweet(options.sms_url)
else:
send_sms(options.sms_url)
send_tweet(options.sms_url)