-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_post.py
More file actions
executable file
·38 lines (29 loc) · 789 Bytes
/
init_post.py
File metadata and controls
executable file
·38 lines (29 loc) · 789 Bytes
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
#!/usr/bin/env python3
import sys
import os
from datetime import datetime
def main():
if len(sys.argv) == 0:
print("No arguments supplied")
exit(1)
print(sys.argv)
if len(sys.argv) == 2:
words = sys.argv[1].split('\w')
else:
words = sys.argv[1:]
print('sys.argv[1:]', sys.argv[1:])
print('words', words)
title = ' '.join(words)
fileTitle = '-'.join([x.lower() for x in words])
print('title', title)
pwd = os.path.dirname(os.path.abspath(__file__))
dateString = datetime.now().strftime("%Y-%m-%d")
print('dateString', dateString)
with open(os.path.join(pwd, '_posts', dateString + '-' + fileTitle + '.markdown'), 'w+') as f:
f.write('''---
layout: post
title: {}
---
'''.format(title))
if __name__ == "__main__":
main()