update
This commit is contained in:
92
scrapeje.py
92
scrapeje.py
@@ -8,7 +8,7 @@ from bs4 import BeautifulSoup
|
|||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from jinja2 import Template
|
||||||
|
|
||||||
restaurant_url=''
|
restaurant_url=''
|
||||||
driver=''
|
driver=''
|
||||||
@@ -18,6 +18,7 @@ restaurant_address=''
|
|||||||
tel=''
|
tel=''
|
||||||
result=''
|
result=''
|
||||||
soup = ''
|
soup = ''
|
||||||
|
nristmax = '0'
|
||||||
nome=[]
|
nome=[]
|
||||||
desc=[]
|
desc=[]
|
||||||
npezzi=[]
|
npezzi=[]
|
||||||
@@ -27,6 +28,7 @@ prezzoN=[]
|
|||||||
|
|
||||||
def inputurl():
|
def inputurl():
|
||||||
global restaurant_url
|
global restaurant_url
|
||||||
|
global nristmax
|
||||||
#INPUT
|
#INPUT
|
||||||
#prende l url della pagina justeat del ristorante in input
|
#prende l url della pagina justeat del ristorante in input
|
||||||
print ("\nesempio: https://www.justeat.it/restaurants-pizzeria-la-garganica-bologna/menu")
|
print ("\nesempio: https://www.justeat.it/restaurants-pizzeria-la-garganica-bologna/menu")
|
||||||
@@ -133,7 +135,6 @@ def stora_tutto():
|
|||||||
npezzi.append(None)
|
npezzi.append(None)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
def parserdarubrica():
|
def parserdarubrica():
|
||||||
global parser
|
global parser
|
||||||
global stora_tutto
|
global stora_tutto
|
||||||
@@ -195,8 +196,33 @@ def genera_prezzoN():
|
|||||||
# for x in range(len(nome)): #PER DEBUG
|
# for x in range(len(nome)): #PER DEBUG
|
||||||
# print(prezzoN[x])
|
# 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():
|
def salvainrubrica():
|
||||||
|
global nristmax
|
||||||
maxn=0
|
maxn=0
|
||||||
def trova_nuovo_numero():
|
def trova_nuovo_numero():
|
||||||
global maxn
|
global maxn
|
||||||
@@ -252,6 +278,7 @@ def salvainrubrica():
|
|||||||
os.makedirs("DATI_RUBRICA", exist_ok=True)
|
os.makedirs("DATI_RUBRICA", exist_ok=True)
|
||||||
nristmax=("1" + "-" + nrist + '.html')
|
nristmax=("1" + "-" + nrist + '.html')
|
||||||
shutil.move ('JEmenu.html', f'./DATI_RUBRICA/{nristmax}')
|
shutil.move ('JEmenu.html', f'./DATI_RUBRICA/{nristmax}')
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
rubrica.write('\n')
|
rubrica.write('\n')
|
||||||
rubrica.write(nristmax + '\n')
|
rubrica.write(nristmax + '\n')
|
||||||
@@ -263,6 +290,7 @@ def salvainrubrica():
|
|||||||
#PULISCE
|
#PULISCE
|
||||||
os.remove("JEmenu.html")
|
os.remove("JEmenu.html")
|
||||||
os.remove("rubrica.txt")
|
os.remove("rubrica.txt")
|
||||||
|
os.remove("logo.gif")
|
||||||
|
|
||||||
|
|
||||||
#############################################################################################
|
#############################################################################################
|
||||||
@@ -298,6 +326,14 @@ stampa_liste()
|
|||||||
stampa_info()
|
stampa_info()
|
||||||
genera_prezzoN()
|
genera_prezzoN()
|
||||||
salvainrubrica()
|
salvainrubrica()
|
||||||
|
genera_frontend()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# #PER DEBUG
|
# #PER DEBUG
|
||||||
@@ -319,57 +355,9 @@ salvainrubrica()
|
|||||||
# print("lista prezziN: ",len(prezzoN)) #sono numeri
|
# print("lista prezziN: ",len(prezzoN)) #sono numeri
|
||||||
# print("\n" + "-" * 25 + "\n")
|
# 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
|
#FA SCHIFO
|
||||||
# html += ' var popup = window.open("", "Popup", "width=200,height=100,top=" + ((window.innerHeight - 100) / 2) + ",left=" + ((window.innerWidth - 200) / 2));'
|
# 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 += ' popup.document.write("<p>Prodotto aggiunto</p>");'
|
||||||
# html += ' setTimeout(function(){ popup.close(); }, 1000);'
|
# html += ' setTimeout(function(){ popup.close(); }, 1000);'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
43
template.html
Normal file
43
template.html
Normal 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>
|
||||||
Reference in New Issue
Block a user