From 239bd2cb0854a0ed765ee36410c773c5b7da98ac Mon Sep 17 00:00:00 2001 From: Castro0o Date: Thu, 26 Mar 2020 21:10:12 +0100 Subject: [PATCH] all imgs (parts) of document to document.html template --- query2html.py | 68 +++++++++++++++++++----------------- templates/document.html | 8 +++-- templates/document_part.html | 31 ---------------- 3 files changed, 40 insertions(+), 67 deletions(-) delete mode 100644 templates/document_part.html diff --git a/query2html.py b/query2html.py index 0d51119..81a8add 100644 --- a/query2html.py +++ b/query2html.py @@ -2,7 +2,7 @@ import os, json, sys, urllib from mwclient import Site from pprint import pprint from jinja2 import Template -from functions import pandoc, unpack_response, clean_dir, remove_nonwords +from functions import unpack_response, clean_dir, remove_nonwords from functions import Colors import argparse @@ -79,6 +79,8 @@ with open(os.path.join(wd, 'templates/document_part.html')) as document_html: all_document_parts = '' # to append all content documentslist = [] +document_images = [] + for answer in site.ask(query): # publication_title = '' # print(answer, answer.keys()) @@ -91,48 +93,48 @@ for answer in site.ask(query): print(Colors.GREEN, 'run python3 download_imgs.py to fix the issue', Colors.ENDC) sys.exit() - 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')) - # Todo: Create list of all images from document # TODO: join document_part + document # TODO: look into the template structure of images : columns and rows + document_images.append(img_local) - # RENDER document part - document_part_html = document_part_template.render( - printout_dict=printout_dict, - imgsrc=os.path.join(imgdir, img_info.get('filename')), - text=pagetext_html, - fullurl=fullurl,) - all_document_parts += document_part_html # append resulting html from document part to the previous parts - + # on last File(Part) of Document if printout_dict['Part'] == printout_dict['Partof']: + print(document_images) + # RENDER DOCUMENT # by passing all_document_parts html to document_template content document_html = document_template.render( title=printout_dict.get('Title'), date=printout_dict.get('Date'), + imgslist=document_images, content=all_document_parts) # render document template - htmlpage_fn = "{}.html".format( - remove_nonwords(printout_dict.get('Title')[0]) - ) - with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: - htmlfile.write(document_html) - all_document_parts = '' # Reset all_document_parts - - # add info to documentslist for index creation - documentslist.append({'file': htmlpage_fn, - 'title': printout_dict.get('Title'), - 'date': printout_dict.get('Date'), - 'creator': printout_dict.get('Creator') - }) - -# RENDER index.html from documentslist -index_html = index_template.render(index='Index', - query=query, - documentslist=documentslist) -with open(os.path.join(static_html, 'index.html'), 'w') as htmlfile: - htmlfile.write(index_html) + # print(document_html) + + # htmlpage_fn = "{}.html".format( + # remove_nonwords(printout_dict.get('Title')[0]) + # ) + # with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: + # htmlfile.write(document_html) + # all_document_parts = '' # Reset all_document_parts + + # # add info to documentslist for index creation + # documentslist.append({'file': htmlpage_fn, + # 'title': printout_dict.get('Title'), + # 'date': printout_dict.get('Date'), + # 'creator': printout_dict.get('Creator') + # }) + + # reset document_images list + document_images = [] + + + +# # RENDER index.html from documentslist +# index_html = index_template.render(index='Index', +# query=query, +# documentslist=documentslist) +# with open(os.path.join(static_html, 'index.html'), 'w') as htmlfile: +# htmlfile.write(index_html) diff --git a/templates/document.html b/templates/document.html index 72687fd..0ed3ba0 100644 --- a/templates/document.html +++ b/templates/document.html @@ -7,9 +7,11 @@

{{ title[0] }}

-

-
- {{ content }} +

+
+ {% for img in imgslist %} + + {% endfor %}
diff --git a/templates/document_part.html b/templates/document_part.html deleted file mode 100644 index 18bcebc..0000000 --- a/templates/document_part.html +++ /dev/null @@ -1,31 +0,0 @@ -
- - - -
- {{ text | safe }} -
- - -