From 3a26a881147b32c46b639cdf6f6e2fad0729db06 Mon Sep 17 00:00:00 2001 From: loop Date: Tue, 4 Oct 2022 11:44:40 +0200 Subject: [PATCH] =?UTF-8?q?Modo=20pi=C3=B9=20semplice=20per=20creare=20il?= =?UTF-8?q?=20json=20cos=C3=AC=20da=20debuggarlo=20meglio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dalla riga 90 alla 112, metodo più standard per creare il json (il problema "TypeError: string indices must be integers" sulla serialization di Django c'è ugualmente, ma così il codice è più pulito) --- ScrapeJE.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/ScrapeJE.py b/ScrapeJE.py index e935e5e..2699403 100644 --- a/ScrapeJE.py +++ b/ScrapeJE.py @@ -88,30 +88,18 @@ print("lista prezzi:",len(prezzo)) #sono stringhe ovvero ci sono anche prezzi co #Crea file json formattato per jawanndenn con la lista dei nomi dei prodotti -#scrive le prime righe del json (uguali ogni volta) -with open('jwndn.json', 'w') as jw: - jw.write("{\n") - jw.write(' "lifetime": "month",\n') - jw.write(' "equal_width": true,\n') - jw.write(' "title":') - jw.write('"') - jw.write(nrist) - jw.write('",') - jw.write("\n") - jw.write(' "options": \n') -#inserisce i nomi dei prodotti dalla lista -def writeListJSONFile(filepathname, lista): - with open('./jwndn.json', 'a+') as f: - json.dump(nome, f) +data = {"lifetime": "month", "equal_width": "true", "title": nrist, "options": nome} -writeListJSONFile('./jwndn.json', nome) +print(json.dumps(data)) -#conclude il json con l ultima parentesi graffa -with open('jwndn.json', 'a+') as jw: - jw.write("\n}\n") +def writeListJSONFile(filepathname): + with open('jwndn.json', 'w') as f: + f.write(json.dumps(data)) +writeListJSONFile('./jwndn.json') + # #storare in "tel" il numero di telefono dle ristorante