All pastes #830087 Raw Edit

Mine

public python v1 · immutable
#830087 ·published 2007-12-23 19:28 UTC
rendered paste body
import calendarimport datetimeimport ostoday = datetime.date.today()states = {'month':today.month,'year':today.year,'day':today.day}events = {}##Let's open the file events.txt in order to get the names of the other filesdef openBasicFile ():    f=open('events.txt','r')    filesArr = list(f)    f.close()    filesArr = [elem.strip() for elem in filesArr]    return filesArr def openEventFile():    print 'opening files'    def cmdHandler (cmd):    global events    global states    if (cmd == 'end'):        return ()        print 'File saved you can exit now'    elif (cmd == 'a'):        # Get info about the event        startT = raw_input ('Plese enter start time \n')        endT = raw_input ('Plese enter end time \n')        desc = raw_input ('Plese enter description for the event \n')        #Link the event        tmpKey = "%d%d" % ( states['year'], states['month'])        if tmpKey not in events:            eventDict = { 'start': startT, 'end': endT, 'description':desc}            eventList = [eventDict]            tmpDict = {states['day']: eventList}            events = { "%d%d" % ( states['year'], states['month'] ) : tmpDict }        else:            tmp = states['day']            eventDict = { 'start': startT, 'end': endT, 'description':desc}            if not tmp in events[tmpKey]:                print 'NOOOO list'                eventList = [eventDict]            else:                eventList = events[tmpKey][tmp]                eventList.append(eventDict)                print 'appending'            tmpDict = {states['day']: eventList}            events = { "%d%d" % ( states['year'], states['month'] ) : tmpDict }            return    elif (cmd == 'p'):        if (states['month'] == 1):            states['month'] = 12            states['year'] = states['year']-1        else:            states['month'] = states['month']-1            displayMonth(states['year'],states['month'])        return     elif (cmd == 'n'):        if(states['month'] == 12):                states['month'] = 1                states['year'] = states['year']+1        else:            states['month'] = states['month']+1        displayMonth(states['year'],states['month'])        return    else:                print 'Available commands :\n "a" to add new event\n "p" to get to the previous month\n "n" to get to the next month\n "x" go to x day of the current month\n "end" to exit\n'##Let's handle it if it's an integer# Otherwise it will go to cmdHandlerdef handleInt(cmd):    if  cmd.isdigit():        if ( int(cmd) <= 31):            states['day'] = cmd            printEventDay(states['year'],states['month'],['day'])        else:            print 'Invalid day'    else:        cmdHandler(cmd)        def printEventDay(year,month, day):    tmpKey = "%d%d" % (year,month)    print events    if tmpKey in events:        if day in events[tmpKey]:            for c in events[tmpKey][day]:                print 'You have this events for today',events[tmpKey][day].keys()    def displayMonth(year , month):    calendar.prmonth(year, month)    tmpKey = "%d%d" % (year,month)    #check if there is an entry for givenMonth year    print events    if tmpKey in events:        for c in events[tmpKey]:            print 'There are events on days : ',events[tmpKey].keys()[0]    else:        print ' There are no events on this month'def main():    print 'My calendar version alpha\n'    print 'Please wait while we are loading your info\n\n'    filesArr = openBasicFile()        displayMonth(today.year, today.month)    print '\nYou are at the ',states['day'],' day\n'    while True:        handleInt(raw_input('Please select a command : \n'))        print '\nYou are at the ',states['day'],' day\n'main()