/
make.py
34 lines (25 loc) · 933 Bytes
/
make.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
import sys
import json
import os
path = os.path.dirname(os.path.abspath(__file__))
try:
print "generating blog..."
#read in template information
index = open(os.path.join(path, 'index.dcc'), 'r').read()
entryStyle = open(os.path.join(path, 'entry_style.dcc'), 'r').read()
#read in blog entries from json file
with open(os.path.join(path, 'entries.json'),'r') as data_file:
entries = json.load(data_file)
#style blog entries
styledEntries=""
for entry in entries["entries"]:
styledEntries=styledEntries+'\n'+entryStyle.format(entry["date"],entry["title"],entry["text"])
#add format wrapping
index = index.format(styledEntries)
#write all entries into index
index_file = open(os.path.join(path, 'index.html'), "w")
index_file.write(index)
index_file.close()
except Exception,e:
print str(sys.exc_traceback.tb_lineno) +":"+str(e)
print "done."