Modified the script, removed types, will introduce tags
This commit is contained in:
parent
d6fdc535e7
commit
462aedd1fc
@ -13,6 +13,7 @@
|
|||||||
<div>
|
<div>
|
||||||
{{educationItem.description}}
|
{{educationItem.description}}
|
||||||
</div>
|
</div>
|
||||||
|
<div>Some random text here random text here random text here random text here random text here random text here random text here random text here random text here </div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
[{"info": {"created_timestamp": 1515095948.838848, "title": "Test title"}, "post": [], "type": "project", "id": "test"}, {"info": {"created_timestamp": 1515094644.215065, "title": "cupboard"}, "post": [], "type": "project", "id": "cupboard1"}, {"info": {"created_timestamp": 1515094644.215333, "title": "some things about lxc in arch"}, "post": [], "type": "tech", "id": "lxdarch"}, {"info": {"created_timestamp": 1515094679.342938, "title": "Who said Web 1.0 was dead anyway?"}, "post": [], "type": "blog", "id": "first"}]
|
[{"info": {"created_timestamp": 1515094679.342938, "title": "Who said Web 1.0 was dead anyway?"}, "id": "first"}, {"info": {"created_timestamp": 1515094644.215065, "title": "cupboard"}, "id": "cupboard1"}, {"info": {"created_timestamp": 1515095948.838848, "title": "Test title"}, "id": "test"}, {"info": {"created_timestamp": 1515094644.215333, "title": "some things about lxc in arch"}, "id": "lxdarch"}]
|
||||||
@ -1,57 +1,48 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
import os;
|
import os;
|
||||||
import json;
|
import json;
|
||||||
import time;
|
import time;
|
||||||
|
|
||||||
# each folder in the post folder is a type of post
|
# each folder in the post folder is a type of post
|
||||||
base = '../assets/post'
|
base = '../assets/post'
|
||||||
types = os.listdir(base);
|
posts = os.listdir(base);
|
||||||
outputfile = '../assets/posts.json'
|
outputfile = '../assets/posts.json'
|
||||||
|
|
||||||
# go over the types
|
|
||||||
for type in types:
|
|
||||||
print type
|
|
||||||
|
|
||||||
# build ourselves a json object
|
# build ourselves a json object
|
||||||
jsonresult = [];
|
jsonresult = [];
|
||||||
for type in types:
|
|
||||||
# now read that folder
|
|
||||||
posts = os.listdir(base+"/"+type);
|
|
||||||
|
|
||||||
# each folder in the current one is a post! the name of the folder is the _id_
|
# each folder in the current one is a post! the name of the folder is the _id_
|
||||||
for post in posts:
|
for post in posts:
|
||||||
print('doing post '+post)
|
print('doing post '+post)
|
||||||
postdir = base+"/"+type+"/"+post;
|
postdir = base+"/"+post;
|
||||||
infofile = postdir+"/info.json";
|
infofile = postdir+"/info.json";
|
||||||
print(infofile)
|
print(infofile)
|
||||||
with open(infofile) as j:
|
with open(infofile) as j:
|
||||||
tt = j.read()
|
tt = j.read()
|
||||||
d = json.loads(tt)
|
d = json.loads(tt)
|
||||||
temp = {};
|
temp = {};
|
||||||
temp['type'] = type;
|
temp['id'] = post;
|
||||||
temp['id'] = post;
|
temp['info'] = d;
|
||||||
if 'post' not in temp:
|
|
||||||
temp['post'] = [];
|
|
||||||
temp['info'] = d;
|
|
||||||
|
|
||||||
# have to write the 'modified date' in the info.json of the post if it's not there yet
|
# have to write the 'modified date' in the info.json of the post if it's not there yet
|
||||||
if not d.has_key('created_timestamp'):
|
if not d.has_key('created_timestamp'):
|
||||||
d['created_timestamp'] = time.time()
|
d['created_timestamp'] = time.time()
|
||||||
# persist it in the json file itself
|
# persist it in the json file itself
|
||||||
with open(infofile, 'w') as infooutfile:
|
with open(infofile, 'w') as infooutfile:
|
||||||
json.dump(d, infooutfile, sort_keys=True, indent=4, separators=(',', ': '))
|
json.dump(d, infooutfile, sort_keys=True, indent=4, separators=(',', ': '))
|
||||||
|
|
||||||
# # figure out the last change of any file in the folder
|
# # figure out the last change of any file in the folder
|
||||||
# lastchange = 0;
|
# lastchange = 0;
|
||||||
# contents = os.listdir(postdir);
|
# contents = os.listdir(postdir);
|
||||||
# for contentfile in contents:
|
# for contentfile in contents:
|
||||||
# lastchange = max(lastchange,os.path.getmtime(postdir+"/"+contentfile))
|
# lastchange = max(lastchange,os.path.getmtime(postdir+"/"+contentfile))
|
||||||
# temp['lastmodified'] = lastchange;
|
# temp['lastmodified'] = lastchange;
|
||||||
|
|
||||||
jsonresult.append(temp);
|
jsonresult.append(temp);
|
||||||
|
|
||||||
# completely append the info.json file
|
# completely append the info.json file
|
||||||
|
|
||||||
# print the result of the json parse
|
# print the result of the json parse
|
||||||
print(json.dumps(jsonresult));
|
print(json.dumps(jsonresult));
|
||||||
with open(outputfile, 'w') as outfile:
|
with open(outputfile, 'w') as outfile:
|
||||||
json.dump(jsonresult, outfile)
|
json.dump(jsonresult, outfile)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user