|
|
@ -3,7 +3,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
import urllib2, json, pprint, re
|
|
|
|
import urllib2, json, pprint, re
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
import subprocess, shlex
|
|
|
|
import subprocess, shlex, urllib
|
|
|
|
sid = '1234'
|
|
|
|
sid = '1234'
|
|
|
|
useragent = "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"
|
|
|
|
useragent = "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"
|
|
|
|
endpoint = "http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&"
|
|
|
|
endpoint = "http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&"
|
|
|
@ -131,11 +131,8 @@ def parse_work_page(title, content):
|
|
|
|
work_dict = {}
|
|
|
|
work_dict = {}
|
|
|
|
work_dict['Title']=title
|
|
|
|
work_dict['Title']=title
|
|
|
|
template, extra = (re.findall('\{\{Graduation work\n(.*?)\}\}(.*)', content, re.DOTALL))[0]
|
|
|
|
template, extra = (re.findall('\{\{Graduation work\n(.*?)\}\}(.*)', content, re.DOTALL))[0]
|
|
|
|
print 'template', template,
|
|
|
|
keyval = re.findall('\|(.*?)\=(.*?\n)', template, re.DOTALL) # template's key/value pair
|
|
|
|
print 'extra', extra
|
|
|
|
if extra: #append extra
|
|
|
|
# template's key/value pair
|
|
|
|
|
|
|
|
keyval = re.findall('\|(.*?)\=(.*?\n)', template, re.DOTALL)
|
|
|
|
|
|
|
|
if extra:
|
|
|
|
|
|
|
|
extra = ('Extra', extra)
|
|
|
|
extra = ('Extra', extra)
|
|
|
|
keyval.append(extra) #?
|
|
|
|
keyval.append(extra) #?
|
|
|
|
|
|
|
|
|
|
|
@ -162,8 +159,10 @@ def parse_work(title, content):
|
|
|
|
|
|
|
|
|
|
|
|
if re.match('\{\{\Graduation work', content):
|
|
|
|
if re.match('\{\{\Graduation work', content):
|
|
|
|
template, extra = (re.findall('\{\{Graduation work\n(.*?)\}\}(.*)', content, re.DOTALL))[0]
|
|
|
|
template, extra = (re.findall('\{\{Graduation work\n(.*?)\}\}(.*)', content, re.DOTALL))[0]
|
|
|
|
|
|
|
|
if extra:
|
|
|
|
workdict['Extra'] = extra.encode('utf-8')
|
|
|
|
workdict['Extra'] = extra.encode('utf-8')
|
|
|
|
# template's key/value pair
|
|
|
|
# template's key/value pair
|
|
|
|
|
|
|
|
# Note:Extra value is NOT CAPTURED by this regex
|
|
|
|
keyval = re.findall('\|(.*?)\=(.*?\n)', template, re.DOTALL)
|
|
|
|
keyval = re.findall('\|(.*?)\=(.*?\n)', template, re.DOTALL)
|
|
|
|
for pair in keyval:
|
|
|
|
for pair in keyval:
|
|
|
|
key = pair[0]
|
|
|
|
key = pair[0]
|
|
|
@ -171,19 +170,18 @@ def parse_work(title, content):
|
|
|
|
if 'Creator' in key:
|
|
|
|
if 'Creator' in key:
|
|
|
|
val = val.replace(', ', '')
|
|
|
|
val = val.replace(', ', '')
|
|
|
|
elif 'Thumbnail' in key:
|
|
|
|
elif 'Thumbnail' in key:
|
|
|
|
print 'calling API'
|
|
|
|
|
|
|
|
val = api_thumb_url(val)
|
|
|
|
val = api_thumb_url(val)
|
|
|
|
print 'THUMB', val
|
|
|
|
elif 'Website' in key:
|
|
|
|
|
|
|
|
val = urllib.unquote(val)
|
|
|
|
|
|
|
|
|
|
|
|
workdict[key]=val.encode('utf-8')
|
|
|
|
workdict[key]=val.encode('utf-8')
|
|
|
|
pprint.pprint(workdict)
|
|
|
|
# pprint.pprint(workdict)
|
|
|
|
return workdict
|
|
|
|
return workdict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Conversion Modules
|
|
|
|
# Conversion Modules
|
|
|
|
def pandoc2html(mw_content):
|
|
|
|
def pandoc2html(mw_content):
|
|
|
|
if mw_content:
|
|
|
|
'''convert individual mw sections to html'''
|
|
|
|
mw_content = mw_content.encode('utf-8')
|
|
|
|
mw_content = mw_content.encode('utf-8')
|
|
|
|
# convert from mw to html
|
|
|
|
# convert from mw to html
|
|
|
|
args_echo =shlex.split( ('echo "{}"'.format(mw_content)) )
|
|
|
|
args_echo =shlex.split( ('echo "{}"'.format(mw_content)) )
|
|
|
@ -193,17 +191,6 @@ def pandoc2html(mw_content):
|
|
|
|
html = (p2.communicate())[0]
|
|
|
|
html = (p2.communicate())[0]
|
|
|
|
return html
|
|
|
|
return html
|
|
|
|
|
|
|
|
|
|
|
|
def pandoc(filename, title, creator, date, website, thumbnail, bio, description, extra, template) :
|
|
|
|
|
|
|
|
'''pandoc: convert mediawiki syntax to html'''
|
|
|
|
|
|
|
|
# mw_content = mw_content.encode('utf-8')
|
|
|
|
|
|
|
|
args_echo =shlex.split( ('echo "{}"'.format( extra )) )
|
|
|
|
|
|
|
|
args_pandoc = shlex.split( 'pandoc -s -f mediawiki -t html \
|
|
|
|
|
|
|
|
--template {template} --variable title="{title}" --variable creator="{creator}" --variable date="{date}" --variable website="{website}" --variable website="{website}" --variable thumbnail="{thumbnail}" --variable bio="""{bio}""" -o {filename}'.format(template=template, title=title, creator=creator, date=date, website=website, thumbnail=thumbnail, bio=bio, description=description, extra=extra, filename=filename) )
|
|
|
|
|
|
|
|
print args_pandoc
|
|
|
|
|
|
|
|
p1 = subprocess.Popen(args_echo, stdout=subprocess.PIPE)
|
|
|
|
|
|
|
|
p2 = subprocess.Popen(args_pandoc, stdin=p1.stdout, stdout=subprocess.PIPE)
|
|
|
|
|
|
|
|
html = (p2.communicate())[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def img_fullurl(parent):
|
|
|
|
def img_fullurl(parent):
|
|
|
|
imgs = parent.findall('.//img')
|
|
|
|
imgs = parent.findall('.//img')
|
|
|
|
for img in imgs:
|
|
|
|
for img in imgs:
|
|
|
|