I have a simple web scraping python script that writes results to a .csv file. The script runs each day when I do a particular task (it's attached to another automation process) that I usually do daily. However sometimes I end up triggering it more than once per day, leaving me with additional entries. I only want to add an entry if the .csv file does not contain today's date. At the moment I have this, but it's causing the writer not to write at all.
with open('results.csv', mode='a') as csv_file:
write = True
for line in csv_file:
if line.contains(date.today()):
write = False
if write == True:
writer = csv.writer(csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow([date.today(),mainstream_count,specialist_count])
I'm sure I'm missing something simple here. Any help would be much appreciated.
Thanks, James.
Aucun commentaire:
Enregistrer un commentaire