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.

45 lines
1.6 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
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 create_workpage( work_dict, work_key):
# 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 ''
description = pandoc2html( work_dict['Description'] if 'Description' in work_dict.keys() else '' )
extra = pandoc2html( work_dict['Extra'] if 'Extra' in work_dict.keys() else '')
print 'Graduation_work:', title, 'by', creator
print 'Description:', description
print 'Extra:', extra
print '----------------------'
for key in json_allworks.keys():
graduation_work=json_allworks[key]
create_workpage(graduation_work, key )