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


Python Post.load方法代码示例

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


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

示例1: print_post

# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import load [as 别名]
def print_post(args):
    if 'all' in args.postid:
        posts = Post.load()
    else:
        try:
            ids = [int(x) for x in args.postid]
        except ValueError:
            print('Post IDs should be numbers')
            return
        posts = Post.load(ids)
    if not len(posts):
        print('Post ID(s) not found: {}'.format(' '.join(args.postid)))
        return
    if args.s:
        posts = order_by_date(posts)
    for postid in posts.keys():
        if len(posts[postid]['body']) > 74:
            body = '\n      '.join(trunc(posts[postid]['body'], 74))
        else:
            body = posts[postid]['body']
        print('Title: {}\nPost ID: {}, last modification date: {}\nBody: {}'
              .format(posts[postid]['title'],
                      postid,
                      posts[postid]['date'],
                      body))
        print('-' * 80)
开发者ID:gruzzin,项目名称:test-blog,代码行数:28,代码来源:blog.py

示例2: publish

# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import load [as 别名]
def publish(post_meta):


    doc_id = Post.url_friendly_text(post_meta["title"])
    
    # Open the database
    couch = couchdb.Server()
    db = couch["mrvoxel_blog"]
    
    # Load the database settings
    blog_settings = settings.loadSettings(db)
    
    # Check to see if we have a valid category
    if not post_meta["category"] in blog_settings["blog_categories"]:
        raise ValueError("No such category: %s" % post_meta["category"])
    
    print "checking for [%s]" % doc_id
    
    # Load the post (if it exists in our database)
    post = Post.load(db, doc_id)
    
    # If it exists, warn the user
    if post:
        raw = raw_input("This will replace an existing post of the same title...\nContinue? (y/N)")
        
        # if the existing post is published but we're trying to preview
        if (post["published"] == False) and post_meta["published"]:
            raise ValueError("Cannot yet preview posts that are already published")
        
        if raw != "y":
            print "Canceling publish."
            return None
        else:
            for k, v in post_meta.iteritems():
                if k not in ["published", "title"]:
                    print k
                    post[k] = v
            
            print post
            
            """
            post.markdown = mdtext
            post.html = html
            post.author = author
            post.timestamp = timestamp
            post.published = not preview
            post.title = title
            post.tags = tags
            post.category = category
            """
            
            post.store(db)
    else:
        
        post = Post.create(**post_meta)
        print post["_id"]
        post.store(db)
        print post["_id"]
    return post["_id"]
开发者ID:cgibson,项目名称:titanium-flea,代码行数:61,代码来源:publish.py

示例3: mod_post

# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import load [as 别名]
def mod_post(args):
    posts = Post.load()
    if not args.title and not args.body:
        print('Either title or body are required for post modificaion')
    else:
        p = Post(args.title or posts[args.postid]['title'],
                 args.body or posts[args.postid]['body'],
                 postid=args.postid)
        p.save()
开发者ID:gruzzin,项目名称:test-blog,代码行数:11,代码来源:blog.py

示例4: list_posts

# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import load [as 别名]
def list_posts(args):
    posts = Post.load()
    if args.s:
        post_table(posts, ordered='date')
    else:
        post_table(posts)
开发者ID:gruzzin,项目名称:test-blog,代码行数:8,代码来源:blog.py


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