Calendar of Upcoming Events on your NanoNote

From Qi-Hardware
Jump to: navigation, search

One option for keeping a calendar of events on your NanoNote is the GCal program. You can download a package for the program from here.

GCal is a very powerful program with a bewildering list of options, but one thing it doesn't seem to do is calculate the time remaining between today and each upcoming event.

Here is a short Python program which prints a list of events with the date of each event, the name of the event, and the weeks and days remaining. You can easily modify it to suit your needs.

Here is some sample output from the program:

Mon 10 May: week 11 in 1w 4d
Thu 13 May: Dr.Lee@1030 in 2w 0d
Fri 14 May: amelia's birthday in 2w 1d
Mon 31 May: week 14 in 4w 4d
Mon 07 Jun: biology exam in 5w 4d
Mon 14 Jun: nursing exam in 6w 4d
Tue 15 Jun: vacation in 6w 5d

The list of events should be kept in a text file, for example events.dat. The format is:

YYYYMMDD Event

For example:

20101225 Chrismas Day

This format is very similar to the one used by the GCal program, so if your GCal events file is simple enough, without recurring events and appointments scheduled for specific times, you could use the same events file for both programs.

#!/usr/bin/python

# until.py

# Print a list of events with the date of the event and
# and the number of days and weeks remaining. 

import datetime

# Get today's date and covert it to a date object.
today = datetime.datetime.date(datetime.datetime.now())

# Get a list of events from a file and sort it.
fileLocation = "/mark/events.dat"
file = open(fileLocation, 'r')
data = file.readlines()
file.close()
data.sort()

# For each item in the data list, parse the date and convert it to a
# date object. The date is in the form YYYYMMDD. The rest of the line
# is the event string. 
items = []
for line in data:
    datecode = line[:8]
    # if the line doesn't start with a date, then skip it.
    if len(datecode) != 8 or not datecode.isdigit():
        continue
    yyyy = int(datecode[:4])
    mm = int(datecode[4:6])
    dd = int(datecode[6:])
    when = datetime.date(yyyy, mm , dd)
    event = line[9:-1]
    items.append([when, event])

print
# Use the date object of each item to calculate the time until in
# weeks and days. Pretty print the date, event, and time until.
for item in items:
    whendate, event = item
    whenstring = whendate.strftime("%a %d %b")
    until = whendate - today
    weeks, days = divmod(until.days, 7)
    print "%s: %s in %dw %dd" % (whenstring, event, weeks, days)
Personal tools
Namespaces
Variants
Actions
Navigation
interactive
Toolbox
Print/export