all imgs (parts) of document to document.html template

itempage
Castro0o 5 years ago
parent 9133512ec1
commit 239bd2cb08

@ -2,7 +2,7 @@ import os, json, sys, urllib
from mwclient import Site from mwclient import Site
from pprint import pprint from pprint import pprint
from jinja2 import Template 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 from functions import Colors
import argparse 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 all_document_parts = '' # to append all content
documentslist = [] documentslist = []
document_images = []
for answer in site.ask(query): for answer in site.ask(query):
# publication_title = '' # publication_title = ''
# print(answer, answer.keys()) # 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) print(Colors.GREEN, 'run python3 download_imgs.py to fix the issue', Colors.ENDC)
sys.exit() 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')) img_local = os.path.join(imgdir, img_info.get('filename'))
# Todo: Create list of all images from document
# TODO: join document_part + document # TODO: join document_part + document
# TODO: look into the template structure of images : columns and rows # TODO: look into the template structure of images : columns and rows
document_images.append(img_local)
# RENDER document part # on last File(Part) of Document
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
if printout_dict['Part'] == printout_dict['Partof']: if printout_dict['Part'] == printout_dict['Partof']:
print(document_images)
# RENDER DOCUMENT # RENDER DOCUMENT
# by passing all_document_parts html to document_template content # by passing all_document_parts html to document_template content
document_html = document_template.render( document_html = document_template.render(
title=printout_dict.get('Title'), title=printout_dict.get('Title'),
date=printout_dict.get('Date'), date=printout_dict.get('Date'),
imgslist=document_images,
content=all_document_parts) # render document template content=all_document_parts) # render document template
htmlpage_fn = "{}.html".format( # print(document_html)
remove_nonwords(printout_dict.get('Title')[0])
) # htmlpage_fn = "{}.html".format(
with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: # remove_nonwords(printout_dict.get('Title')[0])
htmlfile.write(document_html) # )
all_document_parts = '' # Reset all_document_parts # with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile:
# htmlfile.write(document_html)
# add info to documentslist for index creation # all_document_parts = '' # Reset all_document_parts
documentslist.append({'file': htmlpage_fn,
'title': printout_dict.get('Title'), # # add info to documentslist for index creation
'date': printout_dict.get('Date'), # documentslist.append({'file': htmlpage_fn,
'creator': printout_dict.get('Creator') # '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, # reset document_images list
documentslist=documentslist) document_images = []
with open(os.path.join(static_html, 'index.html'), 'w') as htmlfile:
htmlfile.write(index_html)
# # 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)

@ -8,8 +8,10 @@
<body> <body>
<h1>{{ title[0] }}</h1> <h1>{{ title[0] }}</h1>
<p><time datetime="{{date}}">{{ date.year }}.{{ date.month }}.{{ date.day }}</time></p> <p><time datetime="{{date}}">{{ date.year }}.{{ date.month }}.{{ date.day }}</time></p>
<div id="content"> <div id="images">
{{ content }} {% for img in imgslist %}
<img src="{{ img}} " />
{% endfor %}
</div> </div>
</body> </body>
</html> </html>

@ -1,31 +0,0 @@
<div class="part">
<div class="img">
<img src="{{ imgsrc }}" />
<a href="https:{{ fullurl }}">{{ fullurl }}</a>
</div>
<div class="text">
{{ text | safe }}
</div>
<div class="metadata">
<h3>Metadata</h3>
{% for key, valuelist in printout_dict.items() %}
<div class="metadata_{{key}}">
{% if key == 'Date' %}
<span class="key">{{key}}</span>
<span class="value">{{valuelist.year}} {{valuelist.month}} {{valuelist.day}}</span>
{% elif key == 'page' %}
<span class="key">{{key|upper}}</span>
<span class="value">{{valuelist}}</span>
{% else %}
{% if valuelist|length > 0 %}
<span class="key">{{key|upper}}</span>
<span class="value">{{valuelist | join(", ")}}</span>
{% endif %}
{% endif %}
</div>
{% endfor %}
</div>
</div>
Loading…
Cancel
Save