Python script to generate date along with day

## expenditure tracker ##

import datetime

day_num={'1':'Monday',
     '2':'Tuesday',
     '3':'Wednesday',
     '4':'Thursday',
     '5':'Friday',
     '6':'Saturday',
     '7':'Sunday'
    }

days_in_months={1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}

num_to_months={1:'January',2:'Febraury',3:'March',4:'April',5:'May',6:'June',7:'July',8:'August',9:'September',10:'October',11:'November',12:'December'}
def ret_month(key):
    if num_to_months.get(key):
        return num_to_months.get(key)
    else:
        return "No month"
def ret_day(key):
    if day_num.get(key):
        return day_num.get(key)
    else:
        return "No day"


def ret_days_in_months(key):
    if days_in_months.get(key):
        return days_in_months.get(key)
    else:
        return "wrong month"


#f=open('1.ods','w') ### for opensource spreadsheet format ###
f=open('1.xls','w')  ### for mircosoft excel format
year=2012
months=12
f.write(str(year))
f.write("\n")
for month in range(1,months+1):
    f.write("\n")
    days_months=ret_days_in_months(month)  
    f.write(ret_month(month)+"\n")
    for day in range(1,days_months+1):
        date=str(day)+'/'+str(month)+'/'+str(year)
        date_split=map(int, date.split('/'))
        x=datetime.date(date_split[-1],date_split[1],date_split[0])
        date=str(date_split[0])+ret_month(date_split[1])+str(date_split[2])
        f.write(date+'\t'+ret_day(str(x.isoweekday())))
        f.write("\n")

    
f.close()
    
    
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s