forked from jdtournier/MRtrix3.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewpost.py
executable file
·100 lines (73 loc) · 2.3 KB
/
newpost.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
#
# Initialise new post for MRtrix website
# Author: Rami Tabbara
#
import sys, getopt, datetime, os
def usage():
print ('''
usage: ./newpost.py [-t, --title] post_title [-a --author] post_author [c --categories] post_categories
OPTIONS:
--title directory where mrtrix source commands reside
--author github handle coressponding to author
--categories list of post categories (optional)
Example:
./newpost.py --title 'My awesome title' --author 'jdtournier' --categories 'awesome feature release'
''')
def main(argv):
title = None
author = None
categories = ''
now = datetime.datetime.now()
timezone = "-0600" #Hard-wire for now
date = now.strftime("%Y-%m-%d %H:%M:00") + " " + timezone
try:
opts, args = getopt.getopt(argv, "t:a:c", ["title=", "author=", "categories="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-t", "--title"):
title = arg
elif opt in ("-a", "--author"):
author = arg
elif opt in ("-c", "--categories"):
categories = arg
if title is None or author is None:
usage()
exit(2)
dirn = "_posts/" + now.strftime("%Y/%m/")
if not os.path.exists(dirn):
os.makedirs(dirn)
filename = dirn + now.strftime("%Y-%m-%d") + "-" + title.replace(" ", "-").lower() + ".md"
filecont = """---
layout: post
title: {}
author: {}
date: {}
categories: {}
---
Place your markdown content here! Uses [kramdown syntax](http://kramdown.gettalong.org/syntax.html).
Below are a few example features that you can incorporate into your post.
Remember to place any images used in `/images/posts` directory.
Code snippets (no highlighting):
~~~
def my_awesome_function():
print 'My awesome function'
~~~
Code snippets (with language highlighting):
{{% highlight python %}}
def my_awesome_function():
print 'My awesome function'
{{% endhighlight %}}
Math snippets (using LaTex syntax)
$$
\oint_{{C}} f(z) \, dz = 2 \pi i \sum Res(f, a_k)
$$
""".format(title, author, date, categories)
writer = open(filename, "w")
writer.write(filecont)
writer.close()
print '\nNew post created at: ' + filename
if __name__ == "__main__":
main(sys.argv[1:])