|
|
|
#! /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 api_thumb_url, pandoc2html
|
|
|
|
#import mmdc_create_json import api_thumb_url
|
|
|
|
json_allworks_file = open('allworks_mmdc.json', 'r') # save json
|
|
|
|
json_allworks = json.loads(json_allworks_file.read())
|
|
|
|
pages_path = 'web/work'
|
|
|
|
|
|
|
|
#def generate_xml():
|
|
|
|
|
|
|
|
|
|
|
|
def create_workpage( allworks_dict, work_key): # replace text content in dict with html nodes, holding the content
|
|
|
|
for key in allworks_dict.keys():
|
|
|
|
print key
|
|
|
|
if key in ['Description', 'Extra']: #need conversion to html, dealing:imgs,<gallery>, vimeo/youtube
|
|
|
|
allworks_dict[key] = pandoc2html( allworks_dict[key] if key in allworks_dict.keys() else '' ) # convert to HTML
|
|
|
|
htmlnode = ET.fromstring(allworks_dict[key]) # make them into node
|
|
|
|
elif key in ['Website']:
|
|
|
|
htmlnode = ET.Element('a', attrib={'href': allworks_dict[key], 'id':key})
|
|
|
|
htmlnode.text = allworks_dict[key]
|
|
|
|
elif key in ['Title']:
|
|
|
|
htmlnode = ET.Element('h1', attrib={'id': key})
|
|
|
|
htmlnode.text
|
|
|
|
elif key in ['Creator', 'Date', 'Bio']:
|
|
|
|
htmlnode = ET.Element('p', attrib={'id': key})
|
|
|
|
htmlnode.text
|
|
|
|
elif key in ['Thumbnail_url']:
|
|
|
|
htmlnode = ET.Element('img', attrib={'src': allworks_dict[key], 'id': key})
|
|
|
|
|
|
|
|
else:
|
|
|
|
htmlnode = None
|
|
|
|
# remove keys with None value?
|
|
|
|
|
|
|
|
print htmlnode
|
|
|
|
allworks_dict[key] = htmlnode
|
|
|
|
allworks_dict.pop('Thumbnail', None) #remove thumnail
|
|
|
|
pprint.pprint(allworks_dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# #p
|
|
|
|
# elif key in ['Thumbnail_url']:
|
|
|
|
# #<img>
|
|
|
|
|
|
|
|
|
|
|
|
# else:
|
|
|
|
# generate_xml()
|
|
|
|
# work_dict[key] = allworks_dict[key] if key in allworks_dict.keys() else ''
|
|
|
|
# print work_dict
|
|
|
|
|
|
|
|
|
|
|
|
for key in json_allworks.keys():
|
|
|
|
graduation_work=json_allworks[key]
|
|
|
|
print graduation_work['Creator']
|
|
|
|
|
|
|
|
# pprint.pprint(graduation_work)
|
|
|
|
|
|
|
|
# purge graduation_work from keys with empty vals
|
|
|
|
# for key in graduation_work:
|
|
|
|
# if graduation_work[key] in [None, '']:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# print graduation_work
|
|
|
|
|
|
|
|
create_workpage(graduation_work, key )
|
|
|
|
print '----------'
|