From 239bd2cb0854a0ed765ee36410c773c5b7da98ac Mon Sep 17 00:00:00 2001 From: Castro0o Date: Thu, 26 Mar 2020 21:10:12 +0100 Subject: [PATCH 1/5] all imgs (parts) of document to document.html template --- query2html.py | 68 +++++++++++++++++++----------------- templates/document.html | 8 +++-- templates/document_part.html | 31 ---------------- 3 files changed, 40 insertions(+), 67 deletions(-) delete mode 100644 templates/document_part.html diff --git a/query2html.py b/query2html.py index 0d51119..81a8add 100644 --- a/query2html.py +++ b/query2html.py @@ -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) diff --git a/templates/document.html b/templates/document.html index 72687fd..0ed3ba0 100644 --- a/templates/document.html +++ b/templates/document.html @@ -7,9 +7,11 @@

{{ title[0] }}

-

-
- {{ content }} +

+
+ {% for img in imgslist %} + + {% endfor %}
diff --git a/templates/document_part.html b/templates/document_part.html deleted file mode 100644 index 18bcebc..0000000 --- a/templates/document_part.html +++ /dev/null @@ -1,31 +0,0 @@ -
- - - -
- {{ text | safe }} -
- - -
From 2636d37b97c37bba69dbe6b3e5119e7c54c319b1 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Thu, 26 Mar 2020 21:13:54 +0100 Subject: [PATCH 2/5] remove document parts leftovers; saving document template rendering to disk --- query2html.py | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/query2html.py b/query2html.py index 81a8add..8ef0332 100644 --- a/query2html.py +++ b/query2html.py @@ -74,9 +74,6 @@ with open(os.path.join(wd, 'templates/index.html')) as document_html: with open(os.path.join(wd, 'templates/document.html')) as document_html: document_template = Template(document_html.read()) -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 = [] document_images = [] @@ -95,7 +92,6 @@ for answer in site.ask(query): img_local = os.path.join(imgdir, img_info.get('filename')) - # TODO: join document_part + document # TODO: look into the template structure of images : columns and rows document_images.append(img_local) @@ -113,28 +109,27 @@ for answer in site.ask(query): content=all_document_parts) # render document template # 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 + 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) - # # 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') - # }) + # 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) +# 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) From e5bcb3ab91f6a6f02c2cedbd39af6f184af951ba Mon Sep 17 00:00:00 2001 From: Castro0o Date: Fri, 27 Mar 2020 09:25:27 +0100 Subject: [PATCH 3/5] generating document html pages with images in 4 columns rows --- query2html.py | 15 ++++++++++----- static/style.css | 19 ++++++++----------- templates/document.html | 32 +++++++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/query2html.py b/query2html.py index 8ef0332..15749de 100644 --- a/query2html.py +++ b/query2html.py @@ -76,7 +76,7 @@ with open(os.path.join(wd, 'templates/document.html')) as document_html: all_document_parts = '' # to append all content documentslist = [] -document_images = [] +doc_imgs = [] for answer in site.ask(query): # publication_title = '' @@ -94,18 +94,23 @@ for answer in site.ask(query): # TODO: look into the template structure of images : columns and rows - document_images.append(img_local) + doc_imgs.append(img_local) # on last File(Part) of Document if printout_dict['Part'] == printout_dict['Partof']: - print(document_images) + print(doc_imgs) + + # organize doc_imgs into a matrix (list of lists) + # each sublist containing 4 items [[0,1,2,3][4,5,6,7],[8,9]] + # for template + doc_imgs_matrix = [doc_imgs[i:i+4] for i in range(0, len(doc_imgs), 4)] # 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, + imgsmatrix=doc_imgs_matrix, content=all_document_parts) # render document template # print(document_html) @@ -123,7 +128,7 @@ for answer in site.ask(query): }) # reset document_images list - document_images = [] + doc_imgs = [] diff --git a/static/style.css b/static/style.css index 27fbd59..f42e415 100644 --- a/static/style.css +++ b/static/style.css @@ -1,14 +1,11 @@ -body{font-size: 12pt;} -div.part {border: 1px solid #e5e5e5; - margin-bottom: 10px; - margin-top: 10px; - padding: 20px;} -div#content img {width: 50%;} +body { + margin: 0; + font-family: Arial, Helvetica, sans-serif; + background-color: #aaa4a0; +} - -div.metadata span.key {color: red; - font-weight: bold;} - -#orc {color:blue;} \ No newline at end of file +div.row {display: inline;} +div.column { display: inline;} +div.column img{ width:25%;} \ No newline at end of file diff --git a/templates/document.html b/templates/document.html index 0ed3ba0..bd3e46f 100644 --- a/templates/document.html +++ b/templates/document.html @@ -8,11 +8,33 @@

{{ title[0] }}

-
- {% for img in imgslist %} - + + + {% for row in imgsmatrix %} +
+ {% for img in row %} +
+ +
+ {% endfor %} +
{% endfor %} -
+ - +{# +
+
+ +
+
+ +
+
+ +
+
+ +
+
+#} \ No newline at end of file From 36642f6e14edf8e7da0f7506e3ca5bb59f71873a Mon Sep 17 00:00:00 2001 From: Castro0o Date: Fri, 27 Mar 2020 09:30:43 +0100 Subject: [PATCH 4/5] relative image path --- query2html.py | 3 +-- static/style.css | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/query2html.py b/query2html.py index 15749de..8a81056 100644 --- a/query2html.py +++ b/query2html.py @@ -54,7 +54,6 @@ if args.dry is True: site = Site(host=args.host, path=args.path) wd = os.path.dirname(os.path.abspath(__file__)) # working directory -imgdir = os.path.join(wd, 'images') imgsjson_fn = os.path.join(wd, 'images.json') with open(imgsjson_fn, 'r') as imgsjson_file: images_info = json.load(imgsjson_file) @@ -90,7 +89,7 @@ for answer in site.ask(query): print(Colors.GREEN, 'run python3 download_imgs.py to fix the issue', Colors.ENDC) sys.exit() - img_local = os.path.join(imgdir, img_info.get('filename')) + img_local = os.path.join('../images', img_info.get('filename')) # TODO: look into the template structure of images : columns and rows diff --git a/static/style.css b/static/style.css index f42e415..662381e 100644 --- a/static/style.css +++ b/static/style.css @@ -6,6 +6,6 @@ body { background-color: #aaa4a0; } -div.row {display: inline;} -div.column { display: inline;} -div.column img{ width:25%;} \ No newline at end of file +div.row {display: inline; } +div.column { display: inline; } +div.column img{ width:24%; } \ No newline at end of file From 201b11de4d133dc282caf28cd33cbee5d7c45776 Mon Sep 17 00:00:00 2001 From: Slayr Date: Wed, 1 Apr 2020 11:31:07 +0200 Subject: [PATCH 5/5] query and css changes --- query2html.py | 9 +- static/style.css | 191 +++++++++++++++++++++++++++++++++++++++- templates/document.html | 85 ++++++++++++++---- templates/index.html | 1 + 4 files changed, 263 insertions(+), 23 deletions(-) diff --git a/query2html.py b/query2html.py index 8a81056..c288fb7 100644 --- a/query2html.py +++ b/query2html.py @@ -102,13 +102,20 @@ for answer in site.ask(query): # organize doc_imgs into a matrix (list of lists) # each sublist containing 4 items [[0,1,2,3][4,5,6,7],[8,9]] # for template - doc_imgs_matrix = [doc_imgs[i:i+4] for i in range(0, len(doc_imgs), 4)] + doc_imgs_matrix = [doc_imgs[i:i+100] for i in range(0, len(doc_imgs), 100)] + + + # 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'), + organization=printout_dict.get('Organization'), + creator=printout_dict.get('Creator'), + format=printout_dict.get('Format'), + topic=printout_dict.get('Topic'), imgsmatrix=doc_imgs_matrix, content=all_document_parts) # render document template # print(document_html) diff --git a/static/style.css b/static/style.css index 662381e..62aea22 100644 --- a/static/style.css +++ b/static/style.css @@ -1,11 +1,196 @@ body { - margin: 0; font-family: Arial, Helvetica, sans-serif; background-color: #aaa4a0; } -div.row {display: inline; } +/*div.row {display: inline; } div.column { display: inline; } -div.column img{ width:24%; } \ No newline at end of file +div.column img{ width:24%; }*/ + +.grid-container { + display: grid; + grid-template-columns: repeat(4, 1fr); + grid-gap: 10px; + position: absolute; + top: 60%; + width: 96%; + height: auto; + left:2%; + /*background-color: blue;*/ + text-align: : center; + z-index: 5; + +} + +.grid-container > div { + position: relative; + /*background-color: green;*/ + text-align: center; + /*padding-bottom: 1%;*/ + z-index: 5; +} + +img { + position: relative; + max-width: 100%; + max-height: 100%; + + /*align-content: center;*/ + +} + +/*links*/ + +a:link { + text-decoration: none; + color: black; +} + +a:visited { + text-decoration: none; + color: blue; +} + +a:hover { + text-decoration: none; + color: blue; +} + +h1 { + position: fixed; + right:0%; + top:3%; + text-align: right; + background-color: grey; + padding: 3px 30px 3px 10px; + z-index: 10; + color: black; + font-size: 28px; +} + +h2{ + position: fixed; + right: 0%; + top: 15%; + text-align: left; + background-color: grey; + color: black; + padding: 3px 3px 3px 30px; + z-index: 10; + font-size: 20px; +} + +.indexlist { + position: absolute; + top:20%; +} + + +/* Grid buttons */ + +.header { + + position: absolute; + text-align: center; + padding: 32px; + top: 30%; + right: 0%; + z-index: 9; + width: auto; + height: auto; +} + +p { + display: inline-block; + position: relative; +} + +.btn { + border: none; + outline: none; + width: 110px; + text-align: center; + padding: 12px 0px; + background-color: grey; + cursor: pointer; + font-size: 18px; + margin-right: 5px; + z-index: 9; +} + +.btn:hover { + background-color: black; + color: blue; +} + +.btn:active { + background-color: black; + color: white; +} + + +.metadata{ + position: fixed; + top:5%; + left:0%; + background-color: ; + width: 40%; + z-index: 10; + opacity: 0.7; +} + +.collapsible { + background-color: #777; + color: white; + cursor: pointer; + padding: 18px; + width: 10%; + height: auto; + border: none; + text-align: right; + outline: none; + font-size: 15px; + z-index: 10; + margin-top: 10px; +} + +.active, .collapsible:hover { + background-color: #555; +} + +.content { + position: relative; + padding: 0px 18px; + max-height: 0; + overflow: hidden; + width: 90%; + transition: max-height 0.2s ease-out; + background-color: grey; + color: white; + z-index: 10; + text-align: right; +} + +.metadata_links { + display: block; + width: 100%; + position: relative; + right: 0%; + padding: 10px; + text-align: left; + /*background-color: blue;*/ + font-size: 18px; +} + +.metadata_organization { + font-size: 14px; +} + + + + +.fbtn { + font-style: italic; +} diff --git a/templates/document.html b/templates/document.html index bd3e46f..9785cb3 100644 --- a/templates/document.html +++ b/templates/document.html @@ -3,15 +3,62 @@ + {{ title[0] }} -

{{ title[0] }}

-

+

{{ title[0] }} ↵

+

+ + + + + + + + + + + + +
+

+

+
+ + {% for row in imgsmatrix %} -
+
{% for img in row %}
@@ -20,21 +67,21 @@
{% endfor %} + -{# -
-
- -
-
- -
-
- -
-
- -
-
-#} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 8e45d6e..505e699 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,6 +3,7 @@ {{title}} +

Resultsss from query:
{{query}}