python 3.4 - Endtime Adds On -


i trying run program display dates , schedule, along have made gui program. when trying load endtimes displays last endtime. here code.

#!/usr/bin/env python3 # module dayplanner import time  def toseconds(v , fmt='%y-%m-%d, %h:%m'):     if type(v) == type( '' ):         seconds = time.mktime( time.strptime(v, fmt) )     elif type(v) == type( time.struct_time ):         seconds == time.mktime( v )     else:         seconds = v     return seconds #--------  class activity:     def __init__(self, activity, start):         t = toseconds(start)         b = toseconds(end)         self.entry = (start, end, activity)         #self.start = start         #self.activity = activity      def __str__(self):         return '{}  {}'.format(self.entry[0], self.entry[1]) #--------  class dayplanner:         def __init__(self, date, fmt='%y-%m-%d'):                 self.fmt = fmt                 self.date = toseconds(date, fmt=fmt)                 self.activities = {}          def add(self, activity, start, end):     # start time!                 t = toseconds(start, '%i:%m%p')                 b = toseconds(end, '%i:%m%p')                 print('add: ', start,t)                 print('end: ', end,b)                 #a = activity(activity, (self.date + t))                 #self.activities.append( )                 if t not in self.activities.keys():                         self.activities[t] = []                         self.activities[b]=[]                 self.activities[t].append(activity)          def delete(self,activity,start):                 try:                         t=toseconds(start, '%i:%m%p')                         if t in self.activities.keys():                                 del self.activities[t]                 except indexerror:                         pass           def __str__(self):                 s= 'dayplanner ' +time.ctime(self.date)+'\n'                 in sorted(self.activities.keys()):                         tt=time.localtime(a)                         acctime=time.strftime('%i:%m%p',tt)                         b in sorted(self.activities.keys()):                                 tb=time.localtime(b)                                 endtime = time.strftime('%i:%m%p',tb)                         item in self.activities[a]:                                 s += '  '+acctime+'  '+endtime+'  '+ item + '\n'                 return s #-------- 

here code gui

#!/usr/bin/env python3 # dayplanner gui - starting point  import dayplanner dp import tkinter tkinter import filedialog import time import pickle  calendar = {}  def addftn():          ds = datestring.get()         starts = startstring.get()         ends = endstring.get()          acts = activitystring.get('1.0',tkinter.end)          print('add:    ', ds,starts,ends,acts)           dp = dp.dayplanner(ds)         dateseconds = dp.toseconds(ds,fmt = '%y-%m-%d')         if dateseconds not in calendar.keys():                 calendar[dateseconds] = dp.dayplanner(ds)         calendar[dateseconds].add(acts, starts,ends)  def removeftn():         ds = datestring.get()         starts = startstring.get()         ends = endstring.get()          acts = activitystring.get('1.0',tkinter.end)          print('delete:    ', ds,starts,ends,acts)          dateseconds = dp.toseconds(ds,fmt = '%y-%m-%d')          if dateseconds not in calendar.keys():                 calendar[dateseconds] = dp.dayplanner(ds)         calendar[dateseconds].delete(acts, starts,ends)   def listftn():         s = '  '          k in sorted(calendar.keys()):                 s+='\n#-------------\n'+time.ctime(k)+'\n'                 s+=str(calendar[k])                 print(s)          activitystring.delete('1.0', tkinter.end)         activitystring.insert(tkinter.end,s)  def saveftn():         fn=filedialog.asksaveasfilename()         open(fn,'wb') h:                 pickle.dump(calendar, h)   def loadftn():         global calendar         fn = filedialog.askopenfilename()         open(fn, 'rb') h:                 calendar = pickle.load(h)  root = tkinter.tk()  datestring = tkinter.entry(root, width=16) startstring = tkinter.entry(root, width=16) endstring = tkinter.entry(root, width=16) activitystring = tkinter.text(root, width=40)  addbtn = tkinter.button(root, text='add', command=addftn) removebtn = tkinter.button(root, text='remove', command=removeftn) listbtn = tkinter.button(root, text='list', command=listftn) loadbtn = tkinter.button(root, text='load', command=loadftn) savebtn = tkinter.button(root, text='save', command =saveftn) quitbtn = tkinter.button(root, text='quit', command=root.quit)  activitystring.grid(column=0, row=0, rowspan=9) datestring.grid(column=1, row=0, sticky='ew') startstring.grid(column=1, row=1, sticky='ew') endstring.grid(column=1, row=2, sticky='ew')  addbtn.grid(column=1, row=4, sticky='nsew') removebtn.grid(column=1, row=5, sticky='nsew') listbtn.grid(column=1, row=6, sticky='nsew') loadbtn.grid(column=1, row=7, sticky='nsew') savebtn.grid(column=1, row=8, sticky='nsew') quitbtn.grid(column=1, row=9, sticky='nsew')  tkinter.mainloop() 

example of problem be: if entered date (2017-02-02) start time (7:00pm) end time(8:00pm) little description (class) works fine. if add (2017-02-02) (9:00pm) (10:00om) (sleep) display endtime 'class' event 7-10 rather 7-8.

thanks help.


Comments