Advertisement
Najeebsk

DIARY.pyw

Nov 21st, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 0 0
  1. from tkinter import Tk, Text, END, Button
  2. from tkcalendar import Calendar
  3. import datetime
  4.  
  5. root = Tk()
  6. root.geometry("1000x630")
  7. root.title("Najeeb Diary")
  8.  
  9. aaj = datetime.datetime.now()
  10. y, m, d = aaj.year, aaj.month, aaj.day
  11. cal = Calendar(root, selectmode="day", year=y, month=m, day=d)
  12. cal.place(x=10, y=10, width=980, height=280)
  13. enter = Text(root)
  14. enter.place(x=10, y=330, width=980, height=290)
  15.  
  16. def randomise(message: str):
  17.     sentence = message
  18.     ascii_values = [ord(char) for char in sentence]
  19.     ans = ""
  20.     for i in ascii_values:
  21.         ans += str(i) + " "
  22.     return ans
  23.    
  24. def derandomise():
  25.     file = open("DBDIARY.txt", "r")
  26.     contents = file.read()
  27.     ascii_values = (contents.strip("[]")).split(" ")
  28.     ans = ""
  29.     if ascii_values != [""]:
  30.         for value in ascii_values:
  31.             if value != "":
  32.                 ans += chr(int(value))
  33.         return ans
  34.     else:
  35.         return ""
  36.  
  37. def reader():
  38.     contents = derandomise()
  39.     d = cal.get_date()
  40.     enter.delete("1.0", END)
  41.     if d in contents:
  42.         ans = contents[
  43.             contents.index(d)
  44.             + len(str(d))
  45.             + 8 : contents.index("#end", contents.index(d) + 1)
  46.         ]
  47.         enter.insert("1.0", ans.strip())
  48.     else:
  49.         enter.insert("1.0", "Not Found!")
  50.  
  51. def writer():
  52.     d = str(cal.get_date())
  53.     y = str(enter.get("1.0", "end-1c"))
  54.     l_old = derandomise()
  55.     finalised_product = ""
  56.     if d in l_old:
  57.         finalised_product = l_old[:l_old.index(d) + 15] + y + l_old[l_old.index("#end") - 1:]
  58.     else:
  59.         date = "#date=[" + cal.get_date() + "]\n"
  60.         entered = str(enter.get("1.0", "end-1c"))
  61.         ans = date + "#text=" + entered + "\n#end\n"
  62.         finalised_product = l_old + ans
  63.     with open("DBDIARY.txt", "w") as f:
  64.         f.writelines(randomise(finalised_product))
  65.  
  66. read = Button(root, text="Read Entry", command=reader)
  67. read.place(x=10, y=300, width=100, height=20)
  68. write = Button(root, text="Write Entry", command=writer)
  69. write.place(x=120, y=300, width=100, height=20)
  70.  
  71. root.mainloop()
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement