-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
45 lines (31 loc) · 830 Bytes
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/env python3
# coding: utf-8
import argparse
from datetime import date
from os import path
post_tpl = '''---
layout: post
title:
tags: []
---
'''
def new_post(title):
d = date.today().strftime('%Y-%m-%d')
title = '-'.join(x.lower() for x in title.split())
filename = '_posts/%s-%s.md' % (d, title)
if path.isfile(filename):
print('File already exists.')
else:
with open(filename, 'w', encoding='utf-8') as fout:
fout.write(post_tpl)
print('File %s created.' % filename)
def parse():
parser = argparse.ArgumentParser(description='util commands')
parser.add_argument('--new', dest='title')
return parser.parse_args()
def main():
args = parse()
if 'title' in args:
new_post(args.title)
if __name__ == '__main__':
main()