コード例 #1
0
ファイル: main.py プロジェクト: kurtisharms/ubcexamcram
    def get(self):
        # replace with your credentials from: https://www.twilio.com/user/account
        account_sid = appconfig.get_twilio_SID()
        auth_token = appconfig.get_twilio_auth_token()
        calling_number = appconfig.get_twilio_calling_number()
        client = TwilioRestClient(account_sid, auth_token)

        # Set timezone to Pacific
        tz = pytz.timezone('America/Vancouver')

        ancestor_key = ndb.Key("TextMessages", "*all*")
        messages = TextMessage.query(TextMessage.post_date == datetime.datetime.now(tz).date(), ancestor=ancestor_key).fetch()
        ancestor_key = ndb.Key("TextAddresses", "*all*")
        numbers = TextAddress.query(ancestor=ancestor_key).fetch()
        numbers_messaged = []
        if len(messages) < 3 and len(numbers) < 200:
            for message in messages:
                for number in numbers:
                    if number.number not in numbers_messaged:
                        try:
                            rv = client.messages.create(to=number.number, from_=calling_number, body=message.content)
                            self.response.write(str(rv))
                            numbers_messaged.append(number.number)
                        except:
                            logging.info("Failed to send to number " + number.number + ". Probably because of blacklist; safe to ignore.")
コード例 #2
0
ファイル: main.py プロジェクト: kurtisharms/ubcexamcram
    def get(self):
        # replace with your credentials from: https://www.twilio.com/user/account
        account_sid = appconfig.get_twilio_SID()
        auth_token = appconfig.get_twilio_auth_token()
        calling_number = appconfig.get_twilio_calling_number()
        client = TwilioRestClient(account_sid, auth_token)

        rv = client.messages.create(to="+16049968785", from_=calling_number, body="FACT: Seventeen hours of sustained wakefulness leads to a decrease in performance equivalent to a blood alcohol-level of 0.05%. Unless you've always wanted to try writing an exam drunk, you should get some sleep.")
        self.response.write(str(rv))