-
Notifications
You must be signed in to change notification settings - Fork 6
/
newauthor
executable file
·49 lines (38 loc) · 1.17 KB
/
newauthor
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
#!/usr/bin/env python
import os
import re
from string import Template
import sys
import yaml
AUTHORDIR = "author/"
AUTHOR_DATA_FILE = "_data/authors.yml"
AUTHORTMPL = """---
layout: author
---
"""
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: ./newauthor <github-username>")
sys.exit(1)
author = sys.argv[1]
filename = AUTHORDIR + author + ".md"
if not os.path.exists(filename):
with open(filename, "w") as f:
f.write(AUTHORTMPL)
print("Created Author page(%s)" % filename)
else:
print("Author page already exists, ignoring..")
author_info = yaml.load(open(AUTHOR_DATA_FILE))
if author_info.get(author, None) is None:
author_info[author] = {
"name": author.capitalize(),
"site": "",
"bio": "",
"twitter": ""
}
with open(AUTHOR_DATA_FILE, 'w') as yaml_file:
yaml.dump(author_info, yaml_file, default_flow_style=False)
print("Updated author information in %s" % AUTHOR_DATA_FILE)
else:
print("Author information is already "
"available in %s, ignoring.." % AUTHOR_DATA_FILE)