コード例 #1
0
ファイル: blog.py プロジェクト: gruzzin/test-blog
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)
コード例 #2
0
ファイル: publish.py プロジェクト: cgibson/titanium-flea
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"]
コード例 #3
0
ファイル: blog.py プロジェクト: gruzzin/test-blog
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()
コード例 #4
0
ファイル: blog.py プロジェクト: gruzzin/test-blog
def list_posts(args):
    posts = Post.load()
    if args.s:
        post_table(posts, ordered='date')
    else:
        post_table(posts)