當前位置: 首頁>>代碼示例>>Python>>正文


Python TwilioRestClient.media方法代碼示例

本文整理匯總了Python中twilio.rest.TwilioRestClient.media方法的典型用法代碼示例。如果您正苦於以下問題:Python TwilioRestClient.media方法的具體用法?Python TwilioRestClient.media怎麽用?Python TwilioRestClient.media使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twilio.rest.TwilioRestClient的用法示例。


在下文中一共展示了TwilioRestClient.media方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: beacon

# 需要導入模塊: from twilio.rest import TwilioRestClient [as 別名]
# 或者: from twilio.rest.TwilioRestClient import media [as 別名]
def beacon(config):
    '''
    Emit a dict name "texts" whose value is a list
    of texts.

    .. code-block:: yaml

        beacons:
          twilio_txt_msg:
            account_sid: "<account sid>"
            auth_token: "<auth token>"
            twilio_number: "+15555555555"
            poll_interval: 10

    poll_interval defaults to 10 seconds
    '''
    log.trace('twilio_txt_msg beacon starting')
    ret = []
    if not all([config['account_sid'], config['auth_token'], config['twilio_number']]):
        return ret
    output = {}
    poll_interval = config.get('poll_interval')
    if not poll_interval:
        # Let's default to polling every 10 secons
        poll_interval = 10
    now = datetime.now()
    if 'twilio_txt_msg' in __context__:
        timedelta = now - __context__['twilio_txt_msg']
        if timedelta.seconds < poll_interval:
            log.trace('Twilio beacon poll interval not met.')
            log.trace('Twilio polling in {0}'.format(poll_interval - timedelta.seconds))
            return ret

    output['texts'] = []
    client = TwilioRestClient(config['account_sid'], config['auth_token'])
    messages = client.messages.list(to=config['twilio_number'])
    log.trace('Num messages: {0}'.format(len(messages)))
    if len(messages) < 1:
        log.trace('Twilio beacon has no texts')
        __context__['twilio_txt_msg'] = now
        return ret

    for message in messages:
        item = {}
        item['id'] = str(message.sid)
        item['body'] = str(message.body)
        item['from'] = str(message.from_)
        item['sent'] = str(message.date_sent)
        item['images'] = []

        if int(message.num_media):
            media = client.media(message.sid).list()
            if len(media):
                for pic in media:
                    item['images'].append(str(pic.uri))
        output['texts'].append(item)
        message.delete()
    __context__['twilio_txt_msg'] = now
    ret.append(output)
    return ret
開發者ID:digideskio,項目名稱:headless,代碼行數:62,代碼來源:twilio_txt_msg.py

示例2: beacon

# 需要導入模塊: from twilio.rest import TwilioRestClient [as 別名]
# 或者: from twilio.rest.TwilioRestClient import media [as 別名]
def beacon(config):
    '''
    Emit a dict name "texts" whose value is a list
    of texts.

    .. code-block:: yaml

        beacons:
          twilio_txt_msg:
            account_sid: "<account sid>"
            auth_token: "<auth token>"
            twilio_number: "+15555555555"
            interval: 10

    '''
    log.trace('twilio_txt_msg beacon starting')
    ret = []
    if not all([config['account_sid'], config['auth_token'], config['twilio_number']]):
        return ret
    output = {}
    output['texts'] = []
    client = TwilioRestClient(config['account_sid'], config['auth_token'])
    messages = client.messages.list(to=config['twilio_number'])
    log.trace('Num messages: {0}'.format(len(messages)))
    if len(messages) < 1:
        log.trace('Twilio beacon has no texts')
        return ret

    for message in messages:
        item = {}
        item['id'] = str(message.sid)
        item['body'] = str(message.body)
        item['from'] = str(message.from_)
        item['sent'] = str(message.date_sent)
        item['images'] = []

        if int(message.num_media):
            media = client.media(message.sid).list()
            if len(media):
                for pic in media:
                    item['images'].append(str(pic.uri))
        output['texts'].append(item)
        message.delete()
    ret.append(output)
    return ret
開發者ID:DaveQB,項目名稱:salt,代碼行數:47,代碼來源:twilio_txt_msg.py

示例3: TwilioRestClient

# 需要導入模塊: from twilio.rest import TwilioRestClient [as 別名]
# 或者: from twilio.rest.TwilioRestClient import media [as 別名]
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "{{ account_sid }}"
auth_token  = "{{ auth_token }}"
client = TwilioRestClient(account_sid, auth_token)

# A list of media objects with the properties described above
medias = client.media('MM800f449d0399ed014aae2bcc0cc2f2ec').list()
開發者ID:looselycoupledlabs,項目名稱:api-snippets,代碼行數:12,代碼來源:list-get-example-4.py

示例4: TwilioClient

# 需要導入模塊: from twilio.rest import TwilioRestClient [as 別名]
# 或者: from twilio.rest.TwilioRestClient import media [as 別名]
class TwilioClient(object):
    CORP_FMT = '''Company: {}
Last price: {:.2f}
Ask: {:.2f}
Bid: {:.2f}'''
    COUNTRY_FMT = '''Country: {}
Population: {:.0f} million
Unemployment rate: {:.3f}%'''

    BASE_FMT = '''
    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
    <Message>{}.</Message>
    </Response>
    '''

    MEDIA_FMT = '''
    <?xml version="1.0" encoding="UTF-8"?>
    <Response>
    <Message>
    <Media>{}</Media>
    <Body>{}.</Body>
    </Message>
    </Response>
    '''


    REJ_FMT = "Nothing recognized."
    PRIV_FMT = "This company is not privately traded."
    OUR_NUM = "+16466473401"


    def __init__(self,
                 tw_client_id=TW_CLIENT_ID,
                 tw_secret_key=TW_SECRET_KEY,
                 tw_app_id=TW_APP_ID):
        self.acc_sid = tw_app_id
        self.twilio = TwilioRestClient(tw_client_id, tw_secret_key)

    @staticmethod
    def _plusify(num):
        return ("+{}" if not "+" in num else "{}").format(num)

    def get_media(self, recvd):
        return self.twilio.media(recvd.sid)


    def _message(self, recvd, body, media=None):
        message = self.twilio.messages.create(
                    body=body,
                    media_url=[media] if media else None,
            to=self._plusify(recvd.sender),
            from_=self.OUR_NUM)

        print "sent message: ", message

    def reject(self, recvd):
        self._message(recvd, self.REJ_FMT)

    def private(self, recvd):
        self._message(recvd, self.PRIV_FMT)

    def accept(self, recvd, best_match, info):
        print "trying to accept ", info
        self._message(recvd,
                      self.CORP_FMT.format(
                          best_match,
                          float(info['PX_LAST']),
                          float(info['PX_ASK']),
                          float(info['PX_BID'])))
    def country(self, recvd, best_match, info):
        self._message(recvd,
                      self.COUNTRY_FMT.format(
                          best_match.capitalize(),
                          float(info['WPOP']),
                          float(info['UNEMP'])))
開發者ID:spencermountain,項目名稱:north_chicago,代碼行數:78,代碼來源:sms.py


注:本文中的twilio.rest.TwilioRestClient.media方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。