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 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)

@ -7,9 +7,11 @@
</head>
<body>
<h1>{{ title[0] }}</h1>
<p><time datetime="{{date}}">{{ date.year }}.{{ date.month }}.{{ date.day }} </time></p>
<div id="content">
{{ content }}
<p><time datetime="{{date}}">{{ date.year }}.{{ date.month }}.{{ date.day }}</time></p>
<div id="images">
{% for img in imgslist %}
<img src="{{ img}} " />
{% endfor %}
</div>
</body>
</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