def cancelEvent(): if not checkIfStart(): print 'No event to cancel' else: try: inFile = open(FILENAME, 'rb') try: start = cPickle.load(inFile) event = start[2] finally: inFile.close() if helpers.promptYesOrNo('Are you sure you want to cancel %s' % event): outFile = open(FILENAME, 'wb') start = (False,) try: cPickle.dump(start, outFile) print '%s cancelled' % event finally: outFile.close() except IOError, e: print 'IOError: %s' % e except IndexError, e: print 'Index Error: %s' % e
def createStartEvent(summary='Did not specify a summary', title=None): if checkIfStart(True): try: inFile = open(FILENAME, 'rb') try: start = cPickle.load(inFile) print 'An event is already in progress. %s started at %s.)' \ % (start[2], start[1]) return finally: inFile.close() except: print '''An event has already been created. Cannot retrieve previous information.''' else: if not title: if not helpers.promptYesOrNo(question="No title was specified? " \ "Are you sure you want to proceed?"): print 'Quitting..' return try: outFile = open(FILENAME, 'wb') try: start = (True, getCurrentTime(), summary, title) cPickle.dump(start, outFile) print 'Starting event, \'%s\', at %s' % (start[1], start[2]) finally: outFile.close() except IOError: print 'Problem saving start time information'
def createEventInterface(): ''' Initilizes a command prompt interface to create a new event. Includes: - start time - end time - title (opt) - location (opt) - details (opt) ''' check = True if helpers.promptYesOrNo("Are you sure you want to create a new event?"): try: while check: st = helpers.promptQuestion("Input start time (Q to quit): ") if st and helpers.validateDateTime(st): check = False else: print '%s is not a valid date time' % st check = True while check: et = helpers.promptQuestion('Input end time (Q to quit): ') if et and helpers.validateDateTime(et): check = False else: print '%s is not a valid date time' % et check = True title = helpers.promptQuestion('Input event title (Optional, leave ' 'blank. Q to quit): ') loc = helpers.promptQuestion('Input location (Optional, leave ' 'blank. Q to quit): ') desc = helpers.promptQuestion('Input description: (Optional, leave ' 'blank. Q to quit): ') except helpers.QuitException: print 'Quitting creating event.' return st = helpers.formatDateTime(st) et = helpers.formatDateTime(et) tup = (st, et, title, loc, desc) return tup else: print 'Cancelling creating an event' return None