renaming: publication --> document

andre
Castro0o 5 years ago
parent 5d4edaaf23
commit 6926a5cfa2

@ -2,6 +2,7 @@ import os, json, re, shlex
import subprocess import subprocess
from datetime import datetime from datetime import datetime
def pandoc(pwd, content, format_in, format_out): def pandoc(pwd, content, format_in, format_out):
# print('HTML content file:', wiki_content_f.name) # print('HTML content file:', wiki_content_f.name)

@ -63,47 +63,41 @@ with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd
site.login(username=user, password=pwd) # login to wiki site.login(username=user, password=pwd) # login to wiki
# read template files # read template files
with open(os.path.join(wd, 'templates/publication.html')) as pub_html: with open(os.path.join(wd, 'templates/document.html')) as pub_html:
pub_template = Template(pub_html.read()) pub_template = Template(pub_html.read())
with open(os.path.join(wd, 'templates/publication_part.html')) as pub_html: with open(os.path.join(wd, 'templates/document_part.html')) as pub_html:
pub_part_template = Template(pub_html.read()) pub_part_template = Template(pub_html.read())
pub_parts_html = '' # to append all content all_document_parts = '' # to append all content
for answer in site.ask(query): for answer in site.ask(query):
publication_title = '' publication_title = ''
print(answer, answer.keys()) print(answer, answer.keys())
printout_dict = unpack_response(answer) printout_dict = unpack_response(answer)
# pprint(printout_dict) # pprint(printout_dict)
img_info = images_info[printout_dict['page']] img_info = images_info[printout_dict['page']] # find corresponding image in images.json
page = site.pages[[printout_dict['page']]] page = site.pages[[printout_dict['page']]] # request that page from wiki
pagetext = page.text() pagetext = page.text()
pagetext_html = pandoc(pwd=wd, content=pagetext, format_in='mediawiki', format_out='html') pagetext_html = pandoc(pwd=wd, content=pagetext, format_in='mediawiki', format_out='html')
img_local = os.path.join(imgdir, img_info.get('filename')) img_local = os.path.join(imgdir, img_info.get('filename'))
# pprint(img_info) # render html for that part of the document
# print(img_local) document_part_html = pub_part_template.render(
# import pdb; pdb.set_trace()
pub_part_html = pub_part_template.render(
imgsrc=os.path.join(imgdir, img_info.get('filename')), imgsrc=os.path.join(imgdir, img_info.get('filename')),
text=pagetext_html, text=pagetext_html,
part=printout_dict.get('Part'), part=printout_dict.get('Part'),
partof=printout_dict.get('Partof')) partof=printout_dict.get('Partof'))
pub_parts_html += pub_part_html # append resulting publication part to the previous parts all_document_parts += document_part_html # append resulting html from document part to the previous parts
if printout_dict['Part'] == printout_dict['Partof']: # when Part == Partof if printout_dict['Part'] == printout_dict['Partof']: # when Part == Partof
# Assemble all parts and save to HTML file # pass all_document_parts html to pub_template content
pub_html = pub_template.render(title=printout_dict.get('Title'), pub_html = pub_template.render(title=printout_dict.get('Title'),
date=printout_dict.get('Date'), date=printout_dict.get('Date'),
content=pub_parts_html) # render publication template content=all_document_parts) # render document template
htmlpage_fn = "{}.html".format(printout_dict.get('Title').replace(" ", "")) htmlpage_fn = "{}.html".format(printout_dict.get('Title').replace(" ", ""))
with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile:
htmlfile.write(pub_html) htmlfile.write(pub_html)
# print(pub_html, '\n') all_document_parts = '' # Reset all_document_parts
pub_parts_html = '' # Reset pub_parts_html
# TODO: include Creator Property value # TODO: include Creator Property value

Loading…
Cancel
Save