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


Python Post.from_cio_message方法代码示例

本文整理汇总了Python中models.Post.from_cio_message方法的典型用法代码示例。如果您正苦于以下问题:Python Post.from_cio_message方法的具体用法?Python Post.from_cio_message怎么用?Python Post.from_cio_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Post的用法示例。


在下文中一共展示了Post.from_cio_message方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dl_after

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import from_cio_message [as 别名]
def dl_after(args):
    """Download posts received after args.date and write them to _posts."""

    git_checkout_branch('gh-pages')

    date = datetime.datetime(*[int(i) for i in args.date.split('-')])
    date -= datetime.timedelta(hours=5)
    tstamp = time.mktime(date.timetuple())

    #Download
    msgs = []

    req = cio_requests.get(
        'https://api.context.io/2.0/accounts/' + aid + '/messages',
        params={'folder': 'thelistserve',
                'include_body': 1,
                'body_type': 'text/plain',
                'date_after': tstamp,
                'sort_order': 'asc',
                }

    )

    if req.json():
        msgs += req.json()
    else:
        print "did not receive json!"
        print "%r" % req.content
        print "terminating without writing out"
        return

    posts = [Post.from_cio_message(m) for m in msgs]

    _write_out(posts)
开发者ID:simon-weber,项目名称:the-listserve-archive,代码行数:36,代码来源:bootstrap.py

示例2: commit_post_data

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import from_cio_message [as 别名]
def commit_post_data(webhook_request_json, branch='gh-pages'):
    """Commit a .html file in _posts/, a .json in data/, and append to the
    cumulative .json in data/."""

    webhook = webhook_request_json  # convenience

    account_id = webhook['account_id']
    msg_id = webhook['message_data']['message_id']

    msg = cio_requests.get(
        "https://api.context.io/2.0/accounts/{aid}/messages/{mid}".format(
            aid=account_id,
            mid=msg_id),
        params={'include_body': 1,
                'body_type': 'text/plain'}
    )

    # context.io responded with a list once?
    app.logger.debug('message response:')
    app.logger.debug(msg.json())

    post = Post.from_cio_message(msg.json())

    path_content_pairs = files_to_create(post)

    githubx.commit(
        repo='the-listserve-archive',
        file_descriptions=[file_description(*pair) for pair in path_content_pairs],
        commit_message="add post (%s)" % post.datestr(),
        branch=branch)
开发者ID:simon-weber,项目名称:the-listserve-archive,代码行数:32,代码来源:tla.py

示例3: test_post_jekyll_conversion

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import from_cio_message [as 别名]
    def test_post_jekyll_conversion(self):
        post = Post.from_cio_message(cio_email)

        #TODO unsure how to properly verify this
        fname, contents = post.to_jekyll_html()

        #Make sure we have enough '-'s.
        self.assertTrue(fname.count('-') >= 3)
开发者ID:pombredanne,项目名称:the-listserve-archive,代码行数:10,代码来源:tests.py

示例4: test_post_from_cio

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import from_cio_message [as 别名]
    def test_post_from_cio(self):
        post = Post.from_cio_message(cio_email)

        self.assertEqual('subject', post.subject)
        self.assertEqual('author', post.author)
        self.assertEqual('p1a\np1b\n\np2a\n\n'.split(),
                         post.body.split())
        self.assertEqual(datetime.date.fromtimestamp(0),
                         datetime.date(*post.date))
开发者ID:pombredanne,项目名称:the-listserve-archive,代码行数:11,代码来源:tests.py

示例5: dl_after

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import from_cio_message [as 别名]
def dl_after(args):
    """Download posts received after args.date, write them out to individual
    json in ./data."""

    date = datetime.datetime(*[int(i) for i in args.date.split('-')])
    date -= datetime.timedelta(hours=5)
    tstamp = time.mktime(date.timetuple())

    #Download
    msgs = []

    req = cio_requests.get(
        'https://api.context.io/2.0/accounts/' + aid + '/messages',
        params={'folder': 'thelistserve',
                'include_body': 1,
                'body_type': 'text/plain',
                'date_after': tstamp,
                'sort_order': 'asc',
                }

    )

    if req.json:
        msgs += req.json
    else:
        print "error:", req
        print "will not continue"
        return

    posts = [Post.from_cio_message(m) for m in msgs]

    #Write out
    git_checkout_branch('gh-pages')
    if not os.path.exists('data'):
        #ignore race condition
        os.makedirs('data')

    for p in posts:
        fn = 'data/%s.json' % p.datestr()
        contents = json.dumps(p)

        with open(fn, 'w') as f:
            f.write(contents)

        print fn
开发者ID:pombredanne,项目名称:the-listserve-archive,代码行数:47,代码来源:bootstrap.py

示例6: commit_post_data

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import from_cio_message [as 别名]
def commit_post_data(webhook_request_json, branch='gh-pages'):
    """Commit a .html file in _posts/, a .json in data/, and append to the
    cumulative .json in data/."""

    webhook = webhook_request_json  # convenience

    account_id = webhook['account_id']
    msg_id = webhook['message_data']['message_id']

    msg = cio_requests.get(
        "https://api.context.io/2.0/accounts/{aid}/messages/{mid}".format(
            aid=account_id,
            mid=msg_id),
        params={'include_body': 1,
                'body_type': 'text/plain'}
    )

    # context.io responded with a list?
    app.logger.debug('message response:')
    app.logger.debug(msg.json)

    post = Post.from_cio_message(msg.json)

    #TODO probably better to make just one commit
    fname, jekyll_html = post.to_jekyll_html()
    githubx.commit(
        repo='the-listserve-archive',
        filepath="_posts/%s" % fname,
        content=jekyll_html,
        commit_message='add post html',
        branch=branch)

    githubx.commit(
        repo='the-listserve-archive',
        filepath="data/%s.json" % post.datestr(),
        content=json.dumps(post),
        commit_message='add post json',
        branch=branch)
开发者ID:pombredanne,项目名称:the-listserve-archive,代码行数:40,代码来源:tla.py

示例7: test_post_json_serialize

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import from_cio_message [as 别名]
    def test_post_json_serialize(self):
        post = Post.from_cio_message(cio_email)

        json_post = json.dumps(post)
        self.assertEqual(post, Post(*json.loads(json_post)))
开发者ID:pombredanne,项目名称:the-listserve-archive,代码行数:7,代码来源:tests.py


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