mmdc_pages.py pandoc conversion working
parent
58210feae8
commit
dc50c39a34
@ -0,0 +1,44 @@
|
|||||||
|
#! /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 )
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue