From 6926a5cfa239ffa38465d708f119364373e1ada3 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Sun, 9 Feb 2020 13:16:35 +0100 Subject: [PATCH] renaming: publication --> document --- functions.py | 1 + query2html.py | 28 ++++++++----------- templates/{publication.html => document.html} | 0 ...blication_part.html => document_part.html} | 0 4 files changed, 12 insertions(+), 17 deletions(-) rename templates/{publication.html => document.html} (100%) rename templates/{publication_part.html => document_part.html} (100%) diff --git a/functions.py b/functions.py index c6742bf..9b3b365 100644 --- a/functions.py +++ b/functions.py @@ -2,6 +2,7 @@ import os, json, re, shlex import subprocess from datetime import datetime + def pandoc(pwd, content, format_in, format_out): # print('HTML content file:', wiki_content_f.name) diff --git a/query2html.py b/query2html.py index 265c817..53a66ea 100644 --- a/query2html.py +++ b/query2html.py @@ -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 # 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()) -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_parts_html = '' # to append all content +all_document_parts = '' # to append all content for answer in site.ask(query): publication_title = '' print(answer, answer.keys()) printout_dict = unpack_response(answer) # pprint(printout_dict) - img_info = images_info[printout_dict['page']] - page = site.pages[[printout_dict['page']]] + img_info = images_info[printout_dict['page']] # find corresponding image in images.json + page = site.pages[[printout_dict['page']]] # request that page from wiki pagetext = page.text() pagetext_html = pandoc(pwd=wd, content=pagetext, format_in='mediawiki', format_out='html') img_local = os.path.join(imgdir, img_info.get('filename')) - # pprint(img_info) - # print(img_local) - # import pdb; pdb.set_trace() - pub_part_html = pub_part_template.render( + # render html for that part of the document + document_part_html = pub_part_template.render( imgsrc=os.path.join(imgdir, img_info.get('filename')), text=pagetext_html, part=printout_dict.get('Part'), 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 - # 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'), 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(" ", "")) - with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: htmlfile.write(pub_html) - # print(pub_html, '\n') - pub_parts_html = '' # Reset pub_parts_html + all_document_parts = '' # Reset all_document_parts # TODO: include Creator Property value diff --git a/templates/publication.html b/templates/document.html similarity index 100% rename from templates/publication.html rename to templates/document.html diff --git a/templates/publication_part.html b/templates/document_part.html similarity index 100% rename from templates/publication_part.html rename to templates/document_part.html