all parts of publication in a single html file

andre
Castro0o 5 years ago
parent 6bec6915f7
commit 5f48f9f364

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

@ -1,3 +1,3 @@
body{font-size: 12pt;}
div#img img {width: 100%;}
div#content img {width: 50%;}

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../static/style.css" />
<title>{{title}}</title>
</head>
<body>
<h1>{{ title }}</h1>
<p><time datetime="{{date}}">{{date}}</time></p>
<div id="content">
{{ content }}
</div>
</body>
</html>

@ -0,0 +1,9 @@
<div class="img">
<img src="{{ imgsrc }}" />
</div>
<div class="text">
{{ text }}
</div>
<div class="part">
Part {{part}} of {{partof}}
</div>
Loading…
Cancel
Save