This commit is contained in:
2023-12-04 00:39:18 +01:00
parent 6437960ec8
commit 5c09b714f5
2 changed files with 86 additions and 55 deletions

View File

@@ -8,7 +8,7 @@ from bs4 import BeautifulSoup
import re
import os
import shutil
from jinja2 import Template
restaurant_url=''
driver=''
@@ -18,6 +18,7 @@ restaurant_address=''
tel=''
result=''
soup = ''
nristmax = '0'
nome=[]
desc=[]
npezzi=[]
@@ -27,6 +28,7 @@ prezzoN=[]
def inputurl():
global restaurant_url
global nristmax
#INPUT
#prende l url della pagina justeat del ristorante in input
print ("\nesempio: https://www.justeat.it/restaurants-pizzeria-la-garganica-bologna/menu")
@@ -133,7 +135,6 @@ def stora_tutto():
npezzi.append(None)
continue
def parserdarubrica():
global parser
global stora_tutto
@@ -195,8 +196,33 @@ def genera_prezzoN():
# for x in range(len(nome)): #PER DEBUG
# print(prezzoN[x])
html=''
def genera_frontend():
# IMPOSTA E GENERA pagina2.html CON IL FILE htmlpage.html
global nome
global desc
global npezzi
global prezzo
global prezzoN
global html
with open("template.html", "r") as file:
template_content = file.read()
template = Template(template_content)
html = template.render(
nrist=nrist,
nome=nome,
desc=desc,
npezzi=npezzi,
prezzo=prezzo,
prezzoN=prezzoN
)
with open("pagina2.html", "w") as file:
file.write(html)
def salvainrubrica():
global nristmax
maxn=0
def trova_nuovo_numero():
global maxn
@@ -252,6 +278,7 @@ def salvainrubrica():
os.makedirs("DATI_RUBRICA", exist_ok=True)
nristmax=("1" + "-" + nrist + '.html')
shutil.move ('JEmenu.html', f'./DATI_RUBRICA/{nristmax}')
if data:
rubrica.write('\n')
rubrica.write(nristmax + '\n')
@@ -263,6 +290,7 @@ def salvainrubrica():
#PULISCE
os.remove("JEmenu.html")
os.remove("rubrica.txt")
os.remove("logo.gif")
#############################################################################################
@@ -290,14 +318,22 @@ if os.path.exists('rubrica.txt') and os.path.exists('./DATI_RUBRICA'):
else:
inputurl()
scraper()
parser()
parser()
stora_tutto()
driver.quit()
stampa_liste()
stampa_info()
genera_prezzoN()
genera_prezzoN()
salvainrubrica()
genera_frontend()
# #PER DEBUG
@@ -319,57 +355,9 @@ salvainrubrica()
# print("lista prezziN: ",len(prezzoN)) #sono numeri
# print("\n" + "-" * 25 + "\n")
# DA RIFARE
# Genera codice HTML
html = "<html><body>"
html += "<h1 style='text-align: center;'>" + nrist + "</h1><br><br>"
for x in range(len(nome)):
html += "<h2 style='text-align: center;'>" + nome[x] + "</h2>"
html += "<p style='text-align: center;'>" + str(desc[x]) + "</p>"
html += "<p style='text-align: center;'>N. pezzi: " + str(npezzi[x]) + "</p>"
html += "<p style='text-align: center;'>Prezzo: " + str(prezzoN[x]) + "€ </p>"
#html += "<div style='text-align: center;'><button onclick=\"aggiungiProdotto('" + nome[x] + "', '" + str(prezzoN[x]) + "')\">+1</button></div>"
html += "<div style='text-align: center;'><button style='font-size: 1.5em;' onclick=\"aggiungiProdotto('" + nome[x] + "', '" + str(prezzoN[x]) + "')\">+1</button></div>"
html += "<br><br>"
html += "<br><hr><h2>Prodotti aggiunti</h2>"
html += "<div id=\"prodottiAggiunti\"></div>"
html += '<div id="total">Total: €<span id="totalValue">0.00</span></div>'
html += "<script>"
html += "var totalValue = 0;"
html += "function aggiungiProdotto(nome, prezzoN) {"
html += " var prodotto = nome + ' (' + Number(prezzoN).toFixed(2) + '€)';"
html += " var box = document.getElementById('prodottiAggiunti');"
html += " box.innerHTML += '<p>' + prodotto + ' <button onclick=\"rimuoviProdotto(this, ' + prezzoN + ')\">-1</button></p>';"
html += " totalValue += parseFloat(prezzoN);"
html += " updateTotal();"
html += "}"
html += "function updateTotal() {"
html += " document.getElementById('totalValue').innerText = totalValue.toFixed(2);"
html += "}"
html += "function rimuoviProdotto(element, prezzoN) {"
html += " totalValue -= parseFloat(prezzoN);"
html += " element.parentNode.remove();"
html += " updateTotal();"
html += "}"
html += "</script>"
html += "</body></html>"
# Salva su file
with open("pagina.html", "w") as file:
file.write(html)
#FA SCHIFO
# html += ' var popup = window.open("", "Popup", "width=200,height=100,top=" + ((window.innerHeight - 100) / 2) + ",left=" + ((window.innerWidth - 200) / 2));'
# html += ' popup.document.write("<p>Prodotto aggiunto</p>");'
# html += ' setTimeout(function(){ popup.close(); }, 1000);'
# html += ' setTimeout(function(){ popup.close(); }, 1000);'

43
template.html Normal file
View File

@@ -0,0 +1,43 @@
<html>
<body>
<body style="background-color: black; color: white">
<h1 style='text-align: center; color: #ff8d1a'>{{ nrist }} </h1><br><br>
<ul>
{% for index in range(nome|length) %}
<h2 style='text-align: center;'>{{ nome[index] }}</h2>
<p style='text-align: center;'>{{ desc[index] }}</p>
<p style='text-align: center;'>Npezzi: {{ npezzi[index] }}</p>
<p style='text-align: center;'>{{ prezzoN[index] }}€</p>
<div style='text-align: center;'><button style='font-size: 1.2em;' onclick="aggiungiProdotto('{{ nome[index] }}', '{{ prezzoN[index] }}')">+1</button></div>
<br><br>
{% endfor %}
</ul>
<br><hr><h2>Prodotti aggiunti</h2>
<div id="prodottiAggiunti"></div>
<div id="total">Total: €<span id="totalValue">0.00</span></div>
<script>
var totalValue = 0;
function aggiungiProdotto(nome, prezzoN) {
var prodotto = nome + ' (' + Number(prezzoN).toFixed(2) + '€)';
var box = document.getElementById('prodottiAggiunti');
box.innerHTML += '<p>' + prodotto + ' <button onclick="rimuoviProdotto(this, ' + prezzoN + ')">-1</button></p>';
totalValue += parseFloat(prezzoN);
updateTotal();
}
function updateTotal() {
document.getElementById('totalValue').innerText = totalValue.toFixed(2);
}
function rimuoviProdotto(element, prezzoN) {
totalValue -= parseFloat(prezzoN);
element.parentNode.remove();
updateTotal();
}
</script>
</body>
</html>