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