本文整理汇总了Python中model.Credentials.all方法的典型用法代码示例。如果您正苦于以下问题:Python Credentials.all方法的具体用法?Python Credentials.all怎么用?Python Credentials.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Credentials
的用法示例。
在下文中一共展示了Credentials.all方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import all [as 别名]
def get(self):
video_url = self.request.get("url")
"""Render the main page."""
logging.info('Inserting timeline item to all users')
users = Credentials.all()
total_users = users.count()
if total_users > 10:
return 'Total user count is %d. Aborting broadcast to save your quota' % (
total_users)
body = {
'notification': {'level': 'DEFAULT'},
'text': video_url,
}
if 'youtube' in video_url:
body['menuItems'] = [{'action' : 'PLAY_VIDEO', 'payload' : video_url}]
batch_responses = _BatchCallback()
batch = BatchHttpRequest(callback=batch_responses.callback)
for user in users:
creds = StorageByKeyName(
Credentials, user.key().name(), 'credentials').get()
mirror_service = util.create_service('mirror', 'v1', creds)
timeline = retrieve_all_timeline_items(mirror_service)
batch.add(
mirror_service.timeline().insert(body=body),
request_id=user.key().name())
batch.execute(httplib2.Http())
self._render_template('')
示例2: _insert_item_all_users
# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import all [as 别名]
def _insert_item_all_users(self):
"""Insert a timeline item to all authorized users."""
logging.info('Inserting timeline item to all users')
users = Credentials.all()
total_users = users.count()
if total_users > 10:
return 'Total user count is %d. Aborting broadcast to save your quota' % (
total_users)
body = {
'text': 'Hello Everyone!',
'notification': {'level': 'DEFAULT'}
}
batch_responses = _BatchCallback()
batch = BatchHttpRequest(callback=batch_responses.callback)
for user in users:
creds = StorageByKeyName(
Credentials, user.key().name(), 'credentials').get()
mirror_service = util.create_service('mirror', 'v1', creds)
batch.add(
mirror_service.timeline().insert(body=body),
request_id=user.key().name())
batch.execute(httplib2.Http())
return 'Successfully sent cards to %d users (%d failed).' % (
batch_responses.success, batch_responses.failure)
示例3: get
# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import all [as 别名]
def get(self):
"""Insert a timeline item to all authorized users."""
logging.info('Inserting horoscopes item to all users')
users = Credentials.all()
total_users = users.count()
scopes = horoscopes.getHoroscopes(self)
body = horoscopes.createHoroscopeBundle(self, scopes)
for user in users:
creds = StorageByKeyName(
Credentials, user.key().name(), 'credentials').get()
mirror_service = util.create_service('mirror', 'v1', creds)
mirror_service.timeline().insert(body=body).execute()
self._render_template()
示例4: _insert_item_all_users
# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import all [as 别名]
def _insert_item_all_users(self):
"""Insert a timeline item to all authorized users."""
logging.info("Inserting timeline item to all users")
users = Credentials.all()
total_users = users.count()
if total_users > 10:
return "Total user count is %d. Aborting broadcast to save your quota" % (total_users)
body = {"text": "Hello Everyone!", "notification": {"level": "DEFAULT"}}
batch_responses = _BatchCallback()
batch = BatchHttpRequest(callback=batch_responses.callback)
for user in users:
creds = StorageByKeyName(Credentials, user.key().name(), "credentials").get()
mirror_service = util.create_service("mirror", "v1", creds)
batch.add(mirror_service.timeline().insert(body=body), request_id=user.key().name())
batch.execute(httplib2.Http())
return "Successfully sent cards to %d users (%d failed)." % (batch_responses.success, batch_responses.failure)
示例5: sendMessage
# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import all [as 别名]
def sendMessage(html):
REPLY_HTML = getReply(html)
body = {
'html': REPLY_HTML,
'notification': {'level': 'DEFAULT'}
}
users = Credentials.all()
batch_responses = _BatchCallback()
batch = BatchHttpRequest(callback=batch_responses.callback)
for user in users:
creds = StorageByKeyName(
Credentials, user.key().name(), 'credentials').get()
mirror_service = util.create_service('mirror', 'v1', creds)
batch.add(
mirror_service.timeline().insert(body=body),
request_id=user.key().name())
batch.execute(httplib2.Http())
return 'Successfully sent cards to %d users (%d failed).' % (
batch_responses.success, batch_responses.failure)
示例6: _insert_playcard_all_users
# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import all [as 别名]
def _insert_playcard_all_users(self):
"""Insert a paginated timeline item."""
logging.info("Inserting paginated timeline item")
users = Credentials.all()
total_users = users.count()
playImg = self.request.get("play-img")
playTitle = self.request.get("play-title")
playDescription = self.request.get("play-desc")
PLAYCARD_HTML = (
"""
<article class='photo' style='left:0px;visibility:visible'>
<img src='"""
+ playImg
+ """' width='100%' height='100%'>
<section><p class='text-normal' style='text-align:right'>"""
+ playTitle
+ """</p></section></article>
"""
)
body = {
"html": PLAYCARD_HTML,
"notification": {"level": "DEFAULT"},
"text": playDescription,
"menuItems": [{"action": "READ_ALOUD"}],
}
batch_responses = _BatchCallback()
batch = BatchHttpRequest(callback=batch_responses.callback)
for user in users:
creds = StorageByKeyName(Credentials, user.key().name(), "credentials").get()
mirror_service = util.create_service("mirror", "v1", creds)
batch.add(mirror_service.timeline().insert(body=body), request_id=user.key().name())
batch.execute(httplib2.Http())
return "Successfully sent playcards to %d players (%d failed)" % (
batch_responses.success,
batch_responses.failure,
)
示例7: _insert_item_all_users
# 需要导入模块: from model import Credentials [as 别名]
# 或者: from model.Credentials import all [as 别名]
def _insert_item_all_users(self):
"""Insert a timeline item to all authorized users."""
logging.info('Inserting timeline item to all users')
users = Credentials.all()
total_users = users.count()
if total_users > 10:
return 'Total user count is %d. Aborting broadcast to save your quota' % (
total_users)
body = {
'text': 'Hello Everyone!',
'notification': {'level': 'DEFAULT'}
}
for user in users:
creds = StorageByKeyName(
Credentials, user.key().name(), 'credentials').get()
mirror_service = util.create_service('mirror', 'v1', creds)
try:
mirror_service.timeline().insert(body=body).execute()
except errors.HttpError, error:
logging.error(
'Unable to send item to user %s: %s', user.key().name(), error)