I'm trying to read a database file to check if it matches the csv file. If it is inside the database but not in the csv file, I want to write the Student number and the status which is absent. Is there a better way to code this since it requires both reading and writing of a csv file?
def absents(cutoff, batch, dates):
with open(batch+"-"+dates+".csv", "r") as file:
reader = csv.DictReader(file)
for row in reader:
studentr = ""
counter = 0
if counter != 1:
with open(batch+"-"+dates+".csv", "a") as file:
fnames = ['Student_Number', 'Datetime', 'Status']
writer = csv.DictWriter(file, fieldnames=fnames)
writer.writerow(
{'Student_Number': studentr, 'Datetime': None, 'Status': "absent"})
counter = 0
for i in range(200000, 200100):
student = db.execute("SELECT * FROM Student WHERE id_number = :i", i=i)
studentnumber = row["Student_Number"]
if student[0]["id_number"] == studentnumber:
studentr = student[0]["id_number"]
counter = 1
return options_mode(cutoff, batch, dates)