-
Notifications
You must be signed in to change notification settings - Fork 1
/
sms.py
97 lines (81 loc) · 3.73 KB
/
sms.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
import requests
TILL_URL = os.environ.get("TILL_URL")
class TillSmsApi():
def __init__(self):
self.to_phone = os.environ.get("BAK_PHONE")
def send_text(self, text):
response = requests.post(TILL_URL, json={
"phone": [self.to_phone],
"text" : text
})
if response.status_code == 200:
print "SMS sent successfully to %s" % self.to_phone
else:
print "SMS to %s failed with response code %s" % (self.to_phone, response.status_code)
"""
*****************************************************************
Alltel [10-digit phone number]@message.alltel.com
Example: [email protected]
AT&T (formerly Cingular) [10-digit phone number]@txt.att.net
[10-digit phone number]@mms.att.net (MMS)
[10-digit phone number]@cingularme.com
Example: [email protected]
Boost Mobile [10-digit phone number]@myboostmobile.com
Example: [email protected]
Nextel (now Sprint Nextel) [10-digit telephone number]@messaging.nextel.com
Example: [email protected]
Sprint PCS (now Sprint Nextel) [10-digit phone number]@messaging.sprintpcs.com
[10-digit phone number]@pm.sprint.com (MMS)
Example: [email protected]
T-Mobile [10-digit phone number]@tmomail.net
Example: [email protected]
US Cellular [10-digit phone number]@email.uscc.net (SMS)
[10-digit phone number]@mms.uscc.net (MMS)
Example: [email protected]
Verizon [10-digit phone number]@vtext.com
[10-digit phone number]@vzwpix.com (MMS)
Example: [email protected]
Virgin Mobile USA [10-digit phone number]@vmobl.com
Example: [email protected]
*****************************************************************
"""
import smtplib
import time
from time import gmtime, strftime, localtime
class SmptpApi():
def __init__(self):
self.username = os.environ.get("GMAIL_USERNAME")
self.password = os.environ.get("GMAIL_PASSWORD")
self.fromaddr = os.environ.get("GMAIL_USERNAME")
self.toaddrs = os.environ.get('BAK_PHONE_EMAIL')
self.subject = 'prices'
def get_full_time(self):
return strftime("%a, %d %b %Y %H:%M:%S", localtime())
def send_text(self, msg):
# The actual mail send
print "Trying to send message to %s at %s" % (self.toaddrs, self.get_full_time())
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(self.username, self.password)
message = ("From: %s\r\n" % self.fromaddr
+ "To: %s\r\n" % self.toaddrs
+ "Subject: %s\r\n" % self.subject
+ "\r\n"
+ msg)
server.sendmail(self.fromaddr, self.toaddrs, message)
server.quit()
from googlevoice import Voice
from googlevoice.util import input
class GoogleVoiceApi():
def __init__(self):
self.voice = Voice()
self.username = os.environ.get("GMAIL_USERNAME")
self.password = os.environ.get("GMAIL_PASSWORD")
self.voice.login(self.username, self.password)
self.to_phone = os.environ.get("BAK_PHONE")
def get_full_time(self):
return strftime("%a, %d %b %Y %H:%M:%S", localtime())
def send_text(self, msg):
print "Trying to send message to %s at %s" % (self.to_phone, self.get_full_time())
return self.voice.send_sms(self.to_phone, msg)