当前位置: 首页>>代码示例>>Python>>正文


Python Entry.put_async方法代码示例

本文整理汇总了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)
开发者ID:appdotnet,项目名称:pourover,代码行数:18,代码来源:feeds.py

示例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))
开发者ID:appdotnet,项目名称:pourover,代码行数:40,代码来源:feeds.py


注:本文中的entry.Entry.put_async方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。