Jun-29-2024, 11:17 PM
im making a task reminder that will send emails and sms reminding of tasks and events. my problem that im stuck with is with saving the data. i chose csv as it is easy to maintain and construct using the pandas library. the problem is where i am extending my send_date_list even though the variable itself is a list, whilst looking inside the csv file i notice that that cell in question is a list in quotation marks meaning that it writes the value as a string and not a list. obviously i need it to be saved as a list in order to search or delete specific entries. an example of my code follows
def save_info(): names_list,due_dates_list,send_date_list,end_date_list,desc_list,phone_number_list,email_address_list=[],[],[],[],[],[],[] """Save the entered reminder information if valid.""" try: df = pd.read_csv("data.csv") except FileNotFoundError: with open("data.csv", "w") as file: writer = csv.writer(file) writer.writerow(["name", "date", "description", "phone number","email address","recurring"]) df = pd.DataFrame(columns=["name", "date", "description", "phone number","email address","recurring"]) client=kickbox.Client(api_key) kbx=client.kickbox() send_date = send_date_ent.get() end_date=end_date_ent.get() due_date=reminder_date_ent.get() to_email_address=email_ent.get() response=kbx.verify(to_email_address) if response.body['result']!="undeliverable": if check_date(send_date): if check_date(due_date): if check_date(end_date): frequency=simpledialog.askinteger(title="Task frequency",prompt="How many days should the task occur?") name = name_ent.get().title() name_parts = name.split(" ") if len(name_parts) < 2: messagebox.showerror(title="Ooooooops", message="You have not entered a first and last name!!\nPlease try again!!") return desc = description_ent.get() phone_number = phone_ent.get() pattern=r'^\d{11}' if len(str(phone_number))!=11 or not re.match(pattern,phone_number): messagebox.showerror(title="OOOOOOps", message="You have not entered a valid phone number!!\n" "Please enter a valid UK phone number \n" "The phone number should be 12 digits long!!\n") return if check_alphabetical(name): if check_alphabetical(desc): if messagebox.askyesno(title="Save this information?", message=f"On the {due_date} {name_parts[1]}, {name_parts[0]} should be reminded to {desc}!!" f"A text message will be sent on {send_date}\n " f"Their phone number is {phone_number}\n" f"Their email address is {to_email_address}\n" f"Do you want to save this information?\n"): saved_data=df.to_dict("records") if var1.get()==1: end_date_index=dates_list_starting_from_today.index(end_date) send_date=dates_list_starting_from_today[:end_date_index:frequency] send_date_list.extend(send_date) recurring=True print(send_date_list) else: due_dates_list.append(due_date) send_date=send_date_ent.get() send_date_list.append(send_date) due_date=reminder_date_ent.get() recurring=False names_list.append(name) desc_list.append(desc) phone_number_list.append(phone_number) email_address_list.append(to_email_address) saved_data.append({"name":names_list,"send date":send_date_list,"due date":due_dates_list,"description":desc_list,"phone number":phone_number_list,"email address":email_address_list,"recurring":recurring}) df2=pd.DataFrame(saved_data) df2.to_csv("data.csv", index=False) send_date_ent.delete(0, END) reminder_date_ent.delete(0,END) name_ent.delete(0, END) description_ent.delete(0, END) phone_ent.delete(0, END) email_ent.delete(0,END) end_date_ent.delete(0,END) else: messagebox.showerror(title="OOOOOops", message="You have entered a date set in the past!!\nPlease remedy this mistake and try again!!") else: messagebox.showerror(title="OOOOOops", message="You have entered a date set in the past!!\nPlease remedy this mistake and try again!!") else: messagebox.showerror(title="OOOOOOPs",message="The email address you entered does not exist!!\nPlease correct the mistake and submit again!!\n")