You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.9 KiB
Python

#! /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
import subprocess, shlex
#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 pandoc2html(mw_content):
if mw_content:
mw_content = mw_content.encode('utf-8')
# convert from mw to html
args_echo =shlex.split( ('echo "{}"'.format(mw_content)) )
args_pandoc = shlex.split( 'pandoc -f mediawiki -t html5' )
p1 = subprocess.Popen(args_echo, stdout=subprocess.PIPE)
p2 = subprocess.Popen(args_pandoc, stdin=p1.stdout, stdout=subprocess.PIPE)
html = (p2.communicate())[0]
return html
#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 '----------'