html exporter basics

This commit is contained in:
Hendrik Schutter 2022-07-20 20:31:49 +02:00
parent f546aa0d06
commit f19249a62a
3 changed files with 221 additions and 0 deletions

79
export_html.py Normal file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Author: Hendrik Schutter, mail@hendrikschutter.com
Date of creation: 2022/07/20
Date of last modification: 2022/07/20
"""
from datetime import datetime
import os
import template_html as thtml
class exporter:
export_dir=""
tsStart = 0
counter = 0
def __init__(self, path):
self.export_dir = path
self.tsStart = datetime.now() #set start time for exporting
try:
os.mkdir(self.export_dir)
except FileExistsError:
pass
def export_comparison(self, seller_listing, competitor_listings):
self.counter +=1
f = open(os.path.join(self.export_dir, str(self.counter) + ".html"), "a")
f.write(thtml.html_comparison_head())
f.close()
def export_startpage():
duration = datetime.timestamp(self.tsStart)
print("Comparison needed: ", duration)
if __name__ == "__main__":
seller_listing_dummy = {
'title': "Seller Title",
'price': float(42.42),
'image': "https://i.ebayimg.com/images/g/7lAAAOSw~ixieBVP/s-l500.jpg",
'url' : "https://www.ebay.de/itm/165508291809"
}
competitor_listings_dummy = [
{
'title': "Competitor Title 01",
'price': float(40.42),
'image': "https://i.ebayimg.com/images/g/7lAAAOSw~ixieBVP/s-l500.jpg",
'url' : "https://www.ebay.de/itm/165508291809"
},
{
'title': "Competitor Title 02",
'price': float(41.42),
'image': "https://i.ebayimg.com/images/g/7lAAAOSw~ixieBVP/s-l500.jpg",
'url' : "https://www.ebay.de/itm/165508291809"
},
{
'title': "Competitor Title 03",
'price': float(42.00),
'image': "https://i.ebayimg.com/images/g/7lAAAOSw~ixieBVP/s-l500.jpg",
'url' : "https://www.ebay.de/itm/165508291809"
}
]
exp = exporter("./html_out/")
exp.export_comparison(seller_listing_dummy, competitor_listings_dummy)

53
html_out/1.html Normal file
View File

@ -0,0 +1,53 @@
<!DOCTYPE html><html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="./data/favicon.ico">
<link rel="icon" sizes="192x192" href="./data/icon.png">
<title>eBay competitor price compare</title>
<link rel="stylesheet" href="./css/w3.css">
<style>
body {
background-color: #000000;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
.holster {
display: flex;
align-items: center;
justify-content: space-between;
flex-flow: column nowrap;
font-family: monospace;
}
.container {
display: flex;
overflow: auto;
outline: 1px dashed lightgray;
flex: none;
}
.container.y {
width: 100%;
height: 500px;
flex-flow: column nowrap;
}
.y.mandatory-scroll-snapping {
scroll-snap-type: y mandatory;
}
.y.proximity-scroll-snapping {
scroll-snap-type: y proximity;
}
.container > .result_scroll_element {
text-align: center;
scroll-snap-align: center;
flex: none;
}
.y.container > .result_scroll_element {
/*line-height: 256px;*/
font-size: 128px;
width: 100%;
height: 100%;
}
</style>
</head>

89
template_html.py Normal file
View File

@ -0,0 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" Author: Hendrik Schutter, mail@hendrikschutter.com
Date of creation: 2022/07/20
Date of last modification: 2022/07/20
"""
def html_comparison_head():
return '''
<!DOCTYPE html><html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="./data/favicon.ico">
<link rel="icon" sizes="192x192" href="./data/icon.png">
<title>eBay competitor price compare</title>
<link rel="stylesheet" href="./css/w3.css">
<style>
body {
background-color: #000000;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
.holster {
display: flex;
align-items: center;
justify-content: space-between;
flex-flow: column nowrap;
font-family: monospace;
}
.container {
display: flex;
overflow: auto;
outline: 1px dashed lightgray;
flex: none;
}
.container.y {
width: 100%;
height: 500px;
flex-flow: column nowrap;
}
.y.mandatory-scroll-snapping {
scroll-snap-type: y mandatory;
}
.y.proximity-scroll-snapping {
scroll-snap-type: y proximity;
}
.container > .result_scroll_element {
text-align: center;
scroll-snap-align: center;
flex: none;
}
.y.container > .result_scroll_element {
/*line-height: 256px;*/
font-size: 128px;
width: 100%;
height: 100%;
}
</style>
</head>
'''
def html_comparison_navigation(counter):
back_link = str((str(counter-1)+".html") if ((counter-1) > 0) else "#")
current = str(counter)
next_link = str((str(counter+1)+".html")) #TODO: test if last one and replace with '#'
return '''
<div class="w3-cell-row">
<div class="w3-container w3-dark-gray w3-cell">
<a class="w3-hover" style="text-decoration: none" href="''' + back_link + '''">
<h1>&larr; Back</h1>
</a>
</div>
<div class="w3-container w3-dark-gray w3-cell w3-center">
<a class="w3-hover" style="text-decoration: none" href="''' + current + '''">
<h1>Compare #''' + current + '''</h1>
</a>
</div>
<div class="w3-container w3-dark-gray w3-cell">
<a class="w3-hover" style="text-decoration: none; text-align: right;" href="''' + next_link + '''">
<h1>&rarr; Next</h1>
</a>
</div>
</div>
'''