本文整理汇总了Python中entry.Entry.put_async方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.put_async方法的具体用法?Python Entry.put_async怎么用?Python Entry.put_async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entry.Entry
的用法示例。
在下文中一共展示了Entry.put_async方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_entry_from_mail
# 需要导入模块: from entry import Entry [as 别名]
# 或者: from entry.Entry import put_async [as 别名]
def create_entry_from_mail(self, mail_message):
plaintext_bodies = mail_message.bodies('text/plain')
html_bodies = mail_message.bodies('text/html')
msg = None
for content_type, body in itertools.chain(plaintext_bodies, html_bodies):
msg = body.decode()
if msg:
break
# Hash the message content, and hour so we won't have the same message within the hour
guid = hashlib.sha256(msg + datetime.now().strftime('%Y%m%d%H')).hexdigest()
entry = Entry(title=mail_message.subject, summary=msg, guid=guid, parent=self.key)
yield entry.put_async()
raise ndb.Return(entry)
示例2: process_feed
# 需要导入模块: from entry import Entry [as 别名]
# 或者: from entry.Entry import put_async [as 别名]
def process_feed(self, overflow, overflow_reason):
# Sync pull down the latest feeds
resp = yield fetch_url(self.feed_url, user_agent=self.user_agent)
parsed_feed = json.loads(resp.content)
posts = parsed_feed.get('data', [])
new_entries = 0
for post in posts:
key = ndb.Key(Entry, post.get('id'), parent=self.key)
entry = yield key.get_async()
if not entry:
standard_resolution = post.get('images', {}).get('standard_resolution')
kwargs = {}
kwargs['image_url'] = standard_resolution.get('url')
kwargs['image_width'] = standard_resolution.get('width')
kwargs['image_height'] = standard_resolution.get('height')
low_resolution = post.get('images', {}).get('low_resolution')
kwargs['thumbnail_image_url'] = low_resolution.get('url')
kwargs['thumbnail_image_width'] = low_resolution.get('width')
kwargs['thumbnail_image_height'] = low_resolution.get('height')
caption = post.get('caption')
if not caption:
kwargs['title'] = '.'
else:
kwargs['title'] = caption.get('text', '')
kwargs['link'] = post.get('link')
kwargs['feed_item'] = post
kwargs['creating'] = False
if overflow:
kwargs['overflow'] = overflow
kwargs['overflow_reason'] = overflow_reason
kwargs['published'] = True
entry = Entry(key=key, guid=post.get('id'), **kwargs)
new_entries += 1
yield entry.put_async()
raise ndb.Return((self, new_entries))