diff --git a/query2html.py b/query2html.py index 0a576ce..a115347 100644 --- a/query2html.py +++ b/query2html.py @@ -63,14 +63,17 @@ 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/document.html')) as pub_html: - pub_template = Template(pub_html.read()) +with open(os.path.join(wd, 'templates/index.html')) as document_html: + index_template = Template(document_html.read()) -with open(os.path.join(wd, 'templates/document_part.html')) as pub_html: - pub_part_template = Template(pub_html.read()) +with open(os.path.join(wd, 'templates/document.html')) as document_html: + document_template = Template(document_html.read()) -all_document_parts = '' # to append all content +with open(os.path.join(wd, 'templates/document_part.html')) as document_html: + document_part_template = Template(document_html.read()) +all_document_parts = '' # to append all content +documentslist = [] for answer in site.ask(query): publication_title = '' # print(answer, answer.keys()) @@ -87,19 +90,32 @@ for answer in site.ask(query): pagetext_html = pandoc(pwd=wd, content=pagetext, format_in='mediawiki', format_out='html') img_local = os.path.join(imgdir, img_info.get('filename')) # render html for that part of the document - document_part_html = pub_part_template.render( + 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']: # when Part == Partof - # pass all_document_parts html to pub_template content - pub_html = pub_template.render(title=printout_dict.get('Title'), + # pass all_document_parts html to document_template content + document_html = document_template.render(title=printout_dict.get('Title'), date=printout_dict.get('Date'), content=all_document_parts) # render document template htmlpage_fn = "{}.html".format(printout_dict.get('Title').replace(" ", "")) + + documentslist.append({'file': htmlpage_fn, + 'title': printout_dict.get('Title'), + 'date': printout_dict.get('Date') + }) + # print(documentslist) + with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: - htmlfile.write(pub_html) + htmlfile.write(document_html) all_document_parts = '' # Reset all_document_parts + +index_html = index_template.render(index='Index', + documentslist=documentslist) +with open(os.path.join(static_html, 'index.html'), 'w') as htmlfile: + htmlfile.write(index_html) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..b08310d --- /dev/null +++ b/templates/index.html @@ -0,0 +1,16 @@ + + +
+ +