Exemple #1
0
def create_post(config):
    flag = 0
    if len(sys.argv) == 1:
        usage()
    elif len(sys.argv) != 1:
        post = Post(config)
        pinyin = PinYin()
        pinyin.load_word()
        string = sys.argv[1]  # Assume that argv[1] is the title user inputed.
        post.title = string
        post.slug = pinyin.hanzi2pinyin_split(string=string, split="-")
        dt = datetime.now()
        post.pub_time = dt.strftime("%Y-%m-%d %H:%M")
        new_post = SAMPLE % (post.title, post.pub_time, post.slug)
        file_title = dt.strftime("%Y-%m-%d") + '-' + post.slug + '.markdown'
        target = os.path.normpath(os.path.join('source/posts', file_title))
        open(target, 'w+').write(new_post)
    else:
        usage()
Exemple #2
0
def create_post(config):
    flag = 0
    if len(sys.argv) == 1:
        usage()
    elif len(sys.argv) != 1:
        post = Post(config)
        pinyin = PinYin()
        pinyin.load_word()
        string = sys.argv[1]  # Assume that argv[1] is the title user inputed.
        post.title = string
        post.slug = pinyin.hanzi2pinyin_split(string=string, split="-")
        dt = datetime.now()
        post.pub_time = dt.strftime("%Y-%m-%d %H:%M")
        new_post = SAMPLE % (post.title, post.pub_time, post.slug)
        file_title = dt.strftime("%Y-%m-%d") + '-' + post.slug + '.markdown'
        target = os.path.normpath(os.path.join('source/posts', file_title))
        open(target, 'w+').write(new_post)
    else:
        usage()