Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.94 KB | None | 0 0
  1. #!usr/bin/python
  2.  
  3. ##Timer Tool - Input
  4.  
  5. import datetime, io, pickle
  6.  
  7. class Database:
  8.     def __init__(self):
  9.         self.tickets = {}
  10.         self.ticket_id = 0
  11.  
  12.     def add_ticket(self):
  13.         print()
  14.         print()
  15.         print("Allright, adding a ticket.")
  16.         link = input("Paste the URL here: ")
  17.         delay = input("How many days to delay this? ")
  18.         delay = int(delay)
  19.         notes = input("Type any notes here: ")
  20.         arf = datetime.date.today()
  21.         thirty = [8, 4, 6, 11]
  22.         disp_month = arf.month
  23.         if arf.month in thirty:
  24.             if arf.day + delay > 30:
  25.                 disp_day = (arf.day-30) + delay
  26.                 if arf.month == 12:
  27.                     disp_month = 1
  28.                 else:
  29.                     disp_month = arf.month + 1
  30.             else:
  31.                 disp_day = arf.day + delay
  32.         elif arf.month == 2:
  33.             if arf.day + delay > 28:
  34.                 disp_day = (arf.day-28) + delay
  35.                 if arf.month == 12:
  36.                     disp_month = 1
  37.                 else:
  38.                     disp_month = arf.month + 1
  39.             else:
  40.                 disp_day = arf.day + delay
  41.         else:
  42.             if arf.day + delay > 31:
  43.                 disp_day = (arf.day-31) + delay
  44.                 if arf.month == 12:
  45.                     disp_month = 1
  46.                 else:
  47.                     disp_month = arf.month + 1
  48.             else:
  49.                 disp_day = arf.day + delay
  50.         self.ticket_id += 1
  51.         mew = self.ticket_id + 1
  52.         mew = str(mew)
  53.         self.tickets[mew] = {}
  54.         arf = self.tickets[mew]
  55.         arf['link'] = link
  56.         arf['disp_mont'] = disp_month
  57.         arf['disp_day'] = disp_day
  58.         arf['notes'] = notes
  59.         print(arf)
  60.         data = open('database.otter', 'wb')
  61.         pickle.dump(self, data)
  62.         data.close()
  63.  
  64.     def display_ticket(self):
  65.         arf = datetime.date.today()
  66.         disp_day = arf.day
  67.         dips_month = arf.month
  68.         ticket_del = []
  69.         for i in self.tickets:
  70.             ter = self.tickets[i]
  71.             if ter['disp_day'] == disp_day:
  72.                 p1_save = open('tickets.txt', 'a')
  73.                 ticket = ""
  74.                 ticket+=str("\n")
  75.                 ticket+=str(self.tickets[i]['link'])
  76.                 ticket+="   "
  77.                 ticket+=str(self.tickets[i]['notes'])
  78.                 ticket_del.append(i)
  79.                 p1_save.write(ticket)
  80.                 p1_save.close()
  81.         for i in ticket_del:
  82.             del self.tickets[i]
  83.  
  84.     def dump_all(self):
  85.             for i in self.tickets:
  86.                 print(i)
  87.                 ticket = ""
  88.                 ticket+=str("\n")
  89.                 ticket+=str(self.tickets[i]['link'])
  90.                 ticket+="   "
  91.                 ticket+=str(self.tickets[i]['notes'])
  92.                 print(ticket)
  93.                 p1_save = open('dump.txt', 'a')
  94.                 p1_save.write(ticket)
  95.                 p1_save.close()
  96.    
  97.  
  98. db = Database()
  99.  
  100. def menu():
  101.     print("Arr, this be Summercat's timer tool")
  102.     print("Arr, and this be the menu.")
  103.     running = 1
  104.     while running:
  105.         print("[A]dd a ticket, or [D]isplay tickets into tickets.txt.\n Or [C]ancel.")
  106.         choice = input("A, B, or C? ")
  107.         if choice.isnumeric():
  108.             print("Avast, type in a proper answer!")
  109.         else:
  110.             choice = choice.lower()
  111.             if choice == 'a':
  112.                 db.add_ticket()
  113.             elif choice == 'b':
  114.                 db.display_ticket()
  115.             elif choice == 'c':
  116.                 running = 0
  117.             elif choice == 'd':
  118.                 db.dump_all()
  119.             elif choice == 'p':
  120.                 for i in db.tickets:
  121.                     print(db.tickets[i])
  122.  
  123.                    
  124. try:
  125.     data = open('database.otter', 'r+b')
  126.     db = pickle.load(data)
  127.     data.close()
  128. except:
  129.     print("Database not found.")
  130. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement