-
Notifications
You must be signed in to change notification settings - Fork 0
/
makepost.py
63 lines (51 loc) · 2.08 KB
/
makepost.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import datetime
import argparse
import operator
from pytz import timezone
# Category
def make_path(category):
post_path = './_posts/'
file_path = './img/posts/'
background_path = './img/posts/background/.png'
languages = 'languages'
if category =='java' or category =='ruby' :
post_path = post_path + languages + '/' + category + '/'
file_path = file_path + languages + '/' + category + '/'
category = "[ " + languages + ', ' +category + ' ]'
else:
post_path = post_path + category + '/'
file_path = file_path + category + '/'
path_list = {'post_path' : post_path, 'file_path' : file_path, 'background_path' : background_path, 'category' : category}
return path_list
def make_post(path_list, title):
time = datetime.datetime.now(timezone('Asia/Seoul'))
current_time = time.strftime('%Y-%m-%d')
post_time = time.strftime('%Y-%m-%d %X %z')
try:
post = open(path_list.get('post_path') + current_time + '-' +title + '.md', 'w', encoding='UTF-8')
post.write('---\n')
post.write('layout: post''\n')
post.write('title: ""''\n')
post.write('subtitle: ""''\n')
post.write('categories: ' + path_list.get('category') + '\n')
post.write('date: ' + post_time + '\n')
post.write('background: ' + path_list.get('background_path') + '\n')
post.write('---\n\n')
post.write('## 1. \n\n')
post.write('![' + title + '-1](' + path_list.get('file_path') + title + '-1.png)\n\n')
post.write('#### 참고\n\n')
post.write('- []()\n')
print("포스트가 생성되었습니다.")
except Exception as e:
print(e)
finally:
post.close
# Parser
parser = argparse.ArgumentParser(description='The Post Maker')
parser.add_argument('category', nargs='?', default='unclassified', type=str, help='database, git, java, ruby, tools')
parser.add_argument('title', type=str, help='Post title')
args = parser.parse_args()
category = args.category
title = args.title
path_list = make_path(category)
make_post(path_list, title)