Modified the script, removed types, will introduce tags

This commit is contained in:
Joachim Nielandt 2018-03-04 16:49:09 +01:00
parent d6fdc535e7
commit 462aedd1fc
11 changed files with 31 additions and 39 deletions

View File

@ -13,6 +13,7 @@
<div>
{{educationItem.description}}
</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>

View File

@ -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"}]

View File

@ -1,57 +1,48 @@
#!/usr/bin/env python
import os;
import json;
import time;
# each folder in the post folder is a type of post
base = '../assets/post'
types = os.listdir(base);
posts = os.listdir(base);
outputfile = '../assets/posts.json'
# go over the types
for type in types:
print type
# build ourselves a json object
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_
for post in posts:
print('doing post '+post)
postdir = base+"/"+type+"/"+post;
infofile = postdir+"/info.json";
print(infofile)
with open(infofile) as j:
tt = j.read()
d = json.loads(tt)
temp = {};
temp['type'] = type;
temp['id'] = post;
if 'post' not in temp:
temp['post'] = [];
temp['info'] = d;
# each folder in the current one is a post! the name of the folder is the _id_
for post in posts:
print('doing post '+post)
postdir = base+"/"+post;
infofile = postdir+"/info.json";
print(infofile)
with open(infofile) as j:
tt = j.read()
d = json.loads(tt)
temp = {};
temp['id'] = post;
temp['info'] = d;
# 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'):
d['created_timestamp'] = time.time()
# persist it in the json file itself
with open(infofile, 'w') as infooutfile:
json.dump(d, infooutfile, sort_keys=True, indent=4, separators=(',', ': '))
# 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'):
d['created_timestamp'] = time.time()
# persist it in the json file itself
with open(infofile, 'w') as infooutfile:
json.dump(d, infooutfile, sort_keys=True, indent=4, separators=(',', ': '))
# # figure out the last change of any file in the folder
# lastchange = 0;
# contents = os.listdir(postdir);
# for contentfile in contents:
# lastchange = max(lastchange,os.path.getmtime(postdir+"/"+contentfile))
# temp['lastmodified'] = lastchange;
# # figure out the last change of any file in the folder
# lastchange = 0;
# contents = os.listdir(postdir);
# for contentfile in contents:
# lastchange = max(lastchange,os.path.getmtime(postdir+"/"+contentfile))
# 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(json.dumps(jsonresult));
with open(outputfile, 'w') as outfile:
json.dump(jsonresult, outfile)
json.dump(jsonresult, outfile)