I get this invalid syntax error:
File "./data_3.0.1.py", line 148
else:
^
SyntaxError: invalid syntax
When I try to run this function:
def funzione_aggiornamento_prezzi(titolo):
pprint ("titolo " + titolo)
#parametri per scaricare lo storico dei prezzi
params = {'item': titolo,
'frequency': 'TBT',
'dataDa':x_giorni_fa()}
try:
r = requests.get(myurl, params=params)
except:
pprint("Si e' verificato un errore")
else:
pprint(r.status_code)
pprint(r.url)
new_list = crea_lista(r)
#codice per scrivere su di un csv da una lista
nomen = "%s.TBT.csv" % (titolo)
csvfile = open(nomen, 'a')
reportwriter = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL)
#codice per scrivere su di un csv
# controllo del numero di rows nel file
with open(nomen,"r") as f:
reader = csv.reader(f,delimiter = ",")
data = list(reader)
row_count = len(data)
if row_count == 0:
for i in new_list:
da_appendere = new_list[i+1]
reportwriter.writerow(da_appendere)
csvfile.close()
#here I get the error
else:
with open(nomen, 'rb') as f:
last_timestamp = f.readlines()[-1].split(",")[0]
#codice per aggiungere al csv solo i nuovi dati
found_it = 0
for i in new_list:
if i == last_timestamp:
found_it = 1
if found_it == 1:
da_appendere = new_list[i+1]
reportwriter.writerow(da_appendere)
csvfile.close()
for i in lista_indici:
funzione_aggiornamento_prezzi(i)
I don't understand what is the problem... Maybe is something very easy but.. I don't really see it!! Basically what I want to do is say to python if the csv file you're opening is empty simply attach the new list otherwise attach only the elements from the new list that are not already in the csv file you just opened
Thanks
Aucun commentaire:
Enregistrer un commentaire