本文整理汇总了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
示例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
示例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()
示例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'])))