From 5c09b714f5867449fc4fb8ad31311df48f13a097 Mon Sep 17 00:00:00 2001 From: scossa Date: Mon, 4 Dec 2023 00:39:18 +0100 Subject: [PATCH] update --- scrapeje.py | 98 ++++++++++++++++++++++----------------------------- template.html | 43 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 55 deletions(-) create mode 100644 template.html diff --git a/scrapeje.py b/scrapeje.py index 149448a..b99fd2c 100644 --- a/scrapeje.py +++ b/scrapeje.py @@ -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 += "

" + nrist + "



" -for x in range(len(nome)): - html += "

" + nome[x] + "

" - html += "

" + str(desc[x]) + "

" - html += "

N. pezzi: " + str(npezzi[x]) + "

" - html += "

Prezzo: " + str(prezzoN[x]) + "€

" - #html += "
" - html += "
" - - html += "

" - -html += "

Prodotti aggiunti

" -html += "
" -html += '
Total: €0.00
' - -html += "" - -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("

Prodotto aggiunto

");' -# html += ' setTimeout(function(){ popup.close(); }, 1000);' \ No newline at end of file +# html += ' setTimeout(function(){ popup.close(); }, 1000);' + + diff --git a/template.html b/template.html new file mode 100644 index 0000000..80c29af --- /dev/null +++ b/template.html @@ -0,0 +1,43 @@ + + + + +

{{ nrist }}



+ + + +

Prodotti aggiunti

+
+
Total: €0.00
+ + + + \ No newline at end of file