diff --git a/.gitignore b/.gitignore index b25c15b..e645833 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +*.pyc \ No newline at end of file diff --git a/mmdc_index.py b/mmdc_index.py new file mode 100755 index 0000000..743037c --- /dev/null +++ b/mmdc_index.py @@ -0,0 +1,42 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +############## +# FROM THE JSON DICTIONARY CREATE AN INDEX PAGE +##### +import xml.etree.ElementTree as ET +import html5lib, urllib2, json, pprint, re +from mmdc_modules import write_html_file + +json_allworks_file = open('allworks_mmdc.json', 'r') # save json +json_allworks = json.loads(json_allworks_file.read()) + +def insert_work(parent, element, work_dict, work_key): + if element == 'Graduation_work thumbnail': + print 'Graduation_work thumbnail' + # Content from json_allworks + thumb = work_dict['Thumbnail_url'] + date = work_dict['Date'] + title = (work_dict['Title']).replace('_', ' ') + creator = work_dict['Creator'] + website = work_dict['Website'] if 'Website' in work_dict.keys() else '' + # HTML Elements + child_div = ET.SubElement(parent, 'div', attrib={'class':'item', 'id':work_key}) + grandchild_a = ET.SubElement(child_div, 'a', attrib={'href':'#', 'class':'work'}) #href article + grandchild_img = ET.SubElement(grandchild_a, 'img', attrib={'class':'work', 'src':thumb}) + grandchild_textbox = ET.SubElement(child_div, 'div', attrib={'class':'work'}) + for content in [title, creator, date]: + grandgrandchild_p = ET.SubElement(grandchild_textbox, 'p', attrib={'class':'work'}) + grandgrandchild_p.text = content + +def edit_index(filepath, json_allworks_dict): + input_file = open(filepath, 'r') + tree = html5lib.parse(input_file, namespaceHTMLElements=False) + div_section02 = (tree.findall(".//div[@id='section02']"))[0] + for key in json_allworks_dict.keys(): + graduation_work=json_allworks_dict[key] + insert_work(div_section02, 'Graduation_work thumbnail', graduation_work, key ) + return tree + +index_tree = edit_index('web/index.html', json_allworks) +write_html_file(index_tree, 'web/index_edited.html') diff --git a/web/pages.json b/web/pages.json deleted file mode 100644 index e69de29..0000000 diff --git a/web/prototype_json.html b/web/prototype_json.html deleted file mode 100644 index ed2e96b..0000000 --- a/web/prototype_json.html +++ /dev/null @@ -1,47 +0,0 @@ - - -
- - - - - - - - -