|
|
|
#! /usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
###########
|
|
|
|
# Testing downloading and converting mw page content to html
|
|
|
|
###########
|
|
|
|
|
|
|
|
# OVER VIEW:
|
|
|
|
# * creating one single html page
|
|
|
|
# request all the pages
|
|
|
|
# build index
|
|
|
|
# build all pages
|
|
|
|
|
|
|
|
import pprint
|
|
|
|
from mmdc_modules import api_request, api_page, api_thumb_url, pandoc2html, parse_work_page, parse_work
|
|
|
|
|
|
|
|
template = open("web/page-template.html", "r")
|
|
|
|
template = template.read()
|
|
|
|
|
|
|
|
# download
|
|
|
|
pageid='16025'#'15965'#Qq #'15986'Jozeph
|
|
|
|
work = 'Mina'#'User:Joak/graduation/catalog1'
|
|
|
|
|
|
|
|
workpage_mw = api_page(pageid, 'content')
|
|
|
|
# parsing workpage_mw
|
|
|
|
workdict = parse_work(work, workpage_mw)
|
|
|
|
for key in workdict.keys():
|
|
|
|
if key in ['Extra', 'Description', 'Bio']:
|
|
|
|
workdict[key] = pandoc2html(workdict[key].encode('utf-8'))
|
|
|
|
# print key
|
|
|
|
# print workdict[key]
|
|
|
|
# print '--------------------'
|
|
|
|
|
|
|
|
template = template.format(title=workdict['Title'], creator=workdict['Creator'], date=workdict['Date'], website=workdict['Website'], thumbnail=workdict['Thumbnail'], bio=workdict['Bio'],description=workdict['Description'], extra=workdict['Extra'] )
|
|
|
|
work_filename = 'web/{}-{}-{}.html'.format(workdict['Date'], (workdict['Creator'].encode('ascii', 'ignore')).replace(' ','_'), pageid)
|
|
|
|
work_file = open(work_filename, "w")
|
|
|
|
work_file.write(template)
|
|
|
|
work_file.close()
|
|
|
|
#template = template.read()
|
|
|
|
|
|
|
|
#print(template)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#for section in [extra, description, bio]:
|
|
|
|
# section = pandoc2html(section.encode('utf-8'))
|
|
|
|
# print section
|
|
|
|
# print '------------'
|
|
|
|
|
|
|
|
#print template
|
|
|
|
#for key in workdict.keys():
|
|
|
|
# print key, workdict[key].encode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#print '----------- html -----'
|
|
|
|
#print html_description
|
|
|
|
#print html_extra
|
|
|
|
|
|
|
|
#print template
|