master
Castro0o 10 years ago
parent 9337f7edd3
commit 622b6d98f2

1
.gitignore vendored

@ -1 +1,2 @@
*~ *~
*.pyc

@ -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')

@ -1,47 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!--script type="text/javascript" src="jquery-1.10.2.js"></script-->
<script type="text/javascript">
var myjson;
function query(workid){
console.log(workid);
var title = myjson[workid]['Title'];
var creator = myjson[workid]['Creator'];
var description = myjson[workid]['Description'];
console.log(title, creator, description);
}
function readJSON(){
$.getJSON( "allworks_mmdc.json", function(data){
myjson=data;
console.log(myjson);
console.log(Object.keys(myjson));
testJSON(myjson);
hover();
})
$('span').hover(
function(){
var thisid = $(this).attr('id')
query(thisid);
}
)
}
</script>
</head>
<body onload="javascript:readJSON();" >
<h3>Testing <span id="9961">JSON</span></h3>
<h3>Hover over the words <span id="9939">JSON</span> and look at the console</h3>
</body>
</html>
Loading…
Cancel
Save