Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.33 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_month'] == disp_month:
  72.                 if ter['disp_day'] <= disp_day:
  73.                     ter['ping'] = 1
  74.             tempmont = 0
  75.             if disp_month == 1:
  76.                 tempmonth = 12
  77.             else:
  78.                 tempmonth = dispmonth - 1
  79.             if ter['dispmonth'] == tempmonth:
  80.                 ter['ping'] = 1
  81.         for i in self.tickets:
  82.             if self.tickets[i]['ping']:
  83.                 p1_save = open('tickets.txt', 'a')
  84.                 ticket = ""
  85.                 ticket+=str("\n")
  86.                 ticket+=str(self.tickets[i]['link'])
  87.                 ticket+="   "
  88.                 ticket+=str(self.tickets[i]['notes'])
  89.                 ticket_del.append(i)
  90.                 p1_save.write(ticket)
  91.                 p1_save.close()
  92.         for i in ticket_del:
  93.             del self.tickets[i]
  94.  
  95.     def dump_all(self):
  96.             for i in self.tickets:
  97.                 print(i)
  98.                 ticket = ""
  99.                 ticket+=str("\n")
  100.                 ticket+=str(self.tickets[i]['link'])
  101.                 ticket+="   "
  102.                 ticket+=str(self.tickets[i]['notes'])
  103.                 print(ticket)
  104.                 p1_save = open('dump.txt', 'a')
  105.                 p1_save.write(ticket)
  106.                 p1_save.close()
  107.    
  108.  
  109. db = Database()
  110.  
  111. def menu():
  112.     print("Arr, this be Summercat's timer tool")
  113.     print("Arr, and this be the menu.")
  114.     running = 1
  115.     while running:
  116.         print("[A]dd a ticket, or [D]isplay tickets into tickets.txt.\n Or [C]ancel.")
  117.         choice = input("A, B, or C? ")
  118.         if choice.isnumeric():
  119.             print("Avast, type in a proper answer!")
  120.         else:
  121.             choice = choice.lower()
  122.             if choice == 'a':
  123.                 db.add_ticket()
  124.             elif choice == 'b':
  125.                 db.display_ticket()
  126.             elif choice == 'c':
  127.                 running = 0
  128.             elif choice == 'd':
  129.                 db.dump_all()
  130.             elif choice == 'p':
  131.                 for i in db.tickets:
  132.                     print(db.tickets[i])
  133.  
  134.                    
  135. try:
  136.     data = open('database.otter', 'r+b')
  137.     db = pickle.load(data)
  138.     data.close()
  139. except:
  140.     print("Database not found.")
  141. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement