コード例 #1
0
ファイル: send_text.py プロジェクト: qbss/court_date_app
def send_text(body, to_number, from_number, auth, debug=True):
    """ Sends text using Twilio
    :param body: message text
    :param to_number: phone number to send to.
    :param from_number: phone number to send from.
    :param auth: Tuple of Twilio sid and authorization token.
    :return: Nothing
    """
    # Your Account Sid and Auth Token from twilio.com/user/account

    account_sid = auth[0]
    auth_token = auth[1]

    print
    if not debug:
        client = rest.TwilioRestClient(account_sid, auth_token)

        body = client.messages.create(body=body,
                                      to=to_number,
                                      from_=from_number)
        print body.sid
    else:
        print "Would have sent the following if debug = False:"
        print

    print "To:", to_number, "  From: ", from_number
    print "Message Text Follows:"
    print body
コード例 #2
0
def send_message(scheduled_message, client=None):
    if client is None:
        client = tr.TwilioRestClient()
    mark_last_sent(scheduled_message)
    client.sms.messages.create(to=scheduled_message.phone_number,
                               from_=TWILIO_NUMBER,
                               body=scheduled_message.message.text)
コード例 #3
0
ファイル: smsaction.py プロジェクト: stevenqzhang/VizAlerts
def get_sms_client():
    """Generic function get an SMS client object. This only works with Twilio at this time."""

    # check to see if there's a provider set
    if config.configs['smsaction.provider'] == None or len(
            config.configs['smsaction.provider']) == 0:
        errormessage = u'SMS Actions are enabled but smsaction.provider value is not set, exiting'
        log.logger.error(errormessage)
        raise ValueError(errormessage)

    # load code for Twilio
    elif config.configs['smsaction.provider'].lower() == 'twilio':
        # these need to be in the global name space to send SMS messages
        global twilio
        import twilio

        global twiliorest
        import twilio.rest as twiliorest

        global smsclient
        smsclient = twiliorest.TwilioRestClient(
            config.configs['smsaction.account_id'],
            config.configs['smsaction.auth_token'])

        return smsclient

    # unknown SMS provider error
    else:
        errormessage = u'SMS Actions are enabled but found unknown smsaction.provider {}, exiting'.format(
            config.configs['smsaction.provider'])
        log.logger.error(errormessage)
        raise ValueError(errormessage)
コード例 #4
0
def make_the_call(experiment_name):
    twilio_client = rest.TwilioRestClient(CONFIG['twilio_account_id'],
                                          CONFIG['twilio_auth_token'])

    call = twilio_client.calls.create(
        to=CONFIG['notification_recipient_number'],
        from_=CONFIG['notification_sender_number'],
        url='https://%s.appspot.com/call_twiml?%s' %
        (CONFIG['appengine_app_id'],
         urllib.urlencode({
             'experiment_name': experiment_name,
             'auth_token': CONFIG['twilio_auth_token']
         })))

    return call.sid
コード例 #5
0
def send_nows_smss():
    now = to_utc(datetime.datetime.now())
    now_hour = datetime.time(hour=now.hour)
    scheduled_messages = ScheduledMessage.query.filter_by(time=now_hour,
                                                          active=True).all()
    scheduled_messages = [
        sm for sm in scheduled_messages if not sm.message.hidden
    ]

    client = tr.TwilioRestClient()

    for message in scheduled_messages:
        if message.daily or message.day_of_week == string.lower(
                now.strftime('%A')):
            current_app.logger.info("Sending message {} at {}".format(
                message, now))
            send_message(message, client=client)
            sleep(1)  # TK TODO hack hacky rate-limiting
コード例 #6
0
import os
import twilio
from twilio import rest

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)

account_sid = os.environ['TWILIO_SID']
auth_token = os.environ['TWILIO_TOKEN']

client = rest.TwilioRestClient(account_sid, auth_token)


def send_message(text, debug=True):
    f = open('phones.csv')
    numbers = f.read().split('\r')

    if debug:
        numbers = ["7035992135", "7033002527"]

    for number in numbers:
        print number
        try:
            message = client.sms.messages.create(body=text,
                                                 to=number,
                                                 from_="+14438981316")
        except twilio.TwilioRestException:
            continue

コード例 #7
0
from twilio import rest
    # put your own credentials here
ACCOUNT_SID = 'ACaf288c67068f2eb80fe060d4367395a1'
AUTH_TOKEN = 'f1a98957b586147107830b655e31811b'

client = rest.TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

client.messages.create(
    to = '+19704585188',
    from_ = '+16502032341',
    body = 'first text from my computer, haha',
)
コード例 #8
0
	def __init__(self, account_sid, auth_token):
		self.client = twilio.TwilioRestClient(
			account_sid,
			auth_token
		)
コード例 #9
0
ファイル: texting.py プロジェクト: kevgh/wheresbrendan
def _GetClient():
    return rest.TwilioRestClient(config.TWILIO_ACCOUNT_SID,
                                 config.TWILIO_AUTH_TOKEN)
コード例 #10
0
from twilio import rest

account = "AC3b730c9fc6be1ff27e792d42f7f50bbd"
token = "a378aafef3590a6eff987bf03b2ffac3"
client = rest.TwilioRestClient(account, token)

message = client.messages.create(to="+1xxxxxxxxxx",
                                 from_="+13474640195",
                                 body="Hello there!")
コード例 #11
0
ファイル: send_text.py プロジェクト: ransomw/udacity
from twilio import rest
import send_text_vars as vars
# Your Account Sid and Auth Token from twilio.com/user/account
client = rest.TwilioRestClient(vars.account_sid, vars.auth_token)
message = client.messages.create(
    body="Hiya",
    to=vars.to_number,  # Replace with your phone number
    from_=vars.from_number)  # Replace with your Twilio number
print message.sid
コード例 #12
0
 def __init__(self):
     """Instantiate a TwilioRestClient based on settings."""
     self.client = rest.TwilioRestClient(
         settings.TWILIO_ACCOUNT_SID,
         settings.TWILIO_AUTH_TOKEN,
         )
コード例 #13
0
def ChoiceNew():
    newMsg = False

    while (newMsg == False):

        print("")
        account_sid = input("Enter your SID Twilio: ")
        print("")
        auth_token = input("Enter your Token Twilio: ")
        print("")
        msgTXT = input("Type your message: ")
        print("")
        toTXT = input(
            "Who is your message, use a phone number? ex: +12555555 ")
        print("")
        fromTXT = input("What is your Twilio phone number? ex: +12555555 ")

        client = rest.TwilioRestClient(account_sid, auth_token)
        message = client.messages.create(
            body=msgTXT,  # Replace with your message
            to=toTXT,  # Replace with your phone number
            from_=fromTXT)  # Replace with your Twilio number

        print("")
        print("Your SID Twilio is: ")
        print(message.sid)

        print("")
        print("Your message: ")
        print(message.body)

        print("")
        print("You sent to: ")
        print(message.to)

        print("")
        print("Who sent: ")
        print(message.from_)

        print("")
        print("")
        print("End of message ^-^")

        print("")
        print("")

        correct2 = False

        while (correct2 == False):
            N_msg = input(
                "Do you want to send another message? ------> Y ou N    ")

            if (N_msg == "y") | (N_msg == "Y"):
                correct2 = True
                newMsg = False
            else:
                if (N_msg == "n") | (N_msg == "N"):
                    print("")
                    print("End of program ^-^")
                    print("")
                    input("Press any key to end . . .")
                    newMsg = True
                    correct2 = True
                else:
                    print("")
                    print("Enter only the characters: y or Y, n or N")
                    print("")
                    correct2 = False