diff --git a/generate_index.py b/generate_index.py index 2a31621..f3d2875 100644 --- a/generate_index.py +++ b/generate_index.py @@ -20,20 +20,54 @@ with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd site.login(username=user, password=pwd) # login to wiki -query = ('[[File:+]][[Title::+]][[Date::+]]|?Title|?Date|?Part|sort=Date,Title,Part|order=asc,asc,asc') +query = ('[[File:+]][[Title::+]][[Date::+]]|?Title|?Date|?Part|?Partof|sort=Title,Part|order=asc,asc') print('Query:', query) + +with open(os.path.join(wd, 'templates/publication.html')) as pub_html: + pub_template = Template(pub_html.read()) + +with open(os.path.join(wd, 'templates/publication_part.html')) as pub_html: + pub_part_template = Template(pub_html.read()) + +pub_parts_html = '' # to append all content + + + + for answer in site.ask(query): + publication_title = '' # print(answer, answer.keys()) printout_dict = unpack_response(answer) - pprint(printout_dict) + # pprint(printout_dict) img_info = images_info[printout_dict['page']] page = site.pages[[printout_dict['page']]] pagetext = page.text() - pagetext_html = pandoc(content=pagetext, format_in='mediawiki', format_out='html') + # TODO: fix pandoc conversion + pagetext_html = pagetext # pandoc(content=pagetext, format_in='mediawiki', format_out='html') img_local = os.path.join(imgdir, img_info.get('filename')) # pprint(img_info) - print(img_local, pagetext_html, '\n') + print(img_local) + pub_part_html = pub_part_template.render( + imgsrc=os.path.join(imgdir, img_info.get('filename')), + text=pagetext_html, + part=printout_dict.get('Part'), + partof=printout_dict.get('Partof')) + pub_parts_html += pub_part_html # append resulting publication part to the previous parts + if printout_dict['Part'] == printout_dict['Partof']: # when Part == Partof + # Assemble all parts and save to HTML file + + pub_html = pub_template.render(title=printout_dict.get('Title'), + date=printout_dict.get('Date'), + content=pub_parts_html) # render publication template + + htmlpage_fn = "{}.html".format(printout_dict.get('Title').replace(" ", "")) + + with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: + htmlfile.write(pub_html) + + print(pub_html, '\n') + pub_parts_html = '' # Reset pub_parts_html # @@ -91,5 +125,3 @@ for answer in site.ask(query): # pageproperties.get('Part').zfill(3) # ) # print(htmlpage_fn) -# with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: -# htmlfile.write(page_html) diff --git a/static/style.css b/static/style.css index 74ec965..6c1190a 100644 --- a/static/style.css +++ b/static/style.css @@ -1,3 +1,3 @@ body{font-size: 12pt;} -div#img img {width: 100%;} \ No newline at end of file +div#content img {width: 50%;} \ No newline at end of file diff --git a/templates/publication.html b/templates/publication.html new file mode 100644 index 0000000..c7f6c90 --- /dev/null +++ b/templates/publication.html @@ -0,0 +1,16 @@ + + + + + + {{title}} + + +

{{ title }}

+

+
+ {{ content }} +
+ + + diff --git a/templates/publication_part.html b/templates/publication_part.html new file mode 100644 index 0000000..c3c3428 --- /dev/null +++ b/templates/publication_part.html @@ -0,0 +1,9 @@ +
+ +
+
+ {{ text }} +
+
+ Part {{part}} of {{partof}} +
\ No newline at end of file