saves the website, email, and password to a JSON file.
()
| 34 | |
| 35 | # ---------------------------- SAVE PASSWORD ------------------------------- # |
| 36 | def save(): |
| 37 | """saves the website, email, and password to a JSON file.""" |
| 38 | website = website_entry.get() |
| 39 | email = email_entry.get() |
| 40 | password = password_entry.get() |
| 41 | new_data = { |
| 42 | website: { |
| 43 | "email": email, |
| 44 | "password": password, |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | if not website or not password: |
| 49 | messagebox.showerror(title="Oops", message="Please don't leave any fields empty!") |
| 50 | return |
| 51 | |
| 52 | is_ok = messagebox.askokcancel(title=website, message=f"These are the details entered: \nEmail: {email} " |
| 53 | f"\nPassword: {password} \nIs it ok to save?") |
| 54 | if is_ok: |
| 55 | try: |
| 56 | with open("data.json", "r") as data_file: |
| 57 | data = json.load(data_file) |
| 58 | except (FileNotFoundError, json.JSONDecodeError): |
| 59 | data = {} |
| 60 | |
| 61 | data.update(new_data) |
| 62 | |
| 63 | with open("data.json", "w") as data_file: |
| 64 | json.dump(data, data_file, indent=4) |
| 65 | |
| 66 | website_entry.delete(0, tk.END) |
| 67 | password_entry.delete(0, tk.END) |
| 68 | |
| 69 | # ---------------------------- FIND PASSWORD ------------------------------- # |
| 70 | def find_password(): |