Hi friends,
This is my first post here. Please forgive me as I am a complete novice with Python. I have experience with HTML and CSS, but my main gig is electronics...So, please excuse me if I am out of line asking this question here!
A friend was helping me build a script using Python to integrate with my Google Calendar. I have a band, and I was wanting an app that could input one date (gig) and then several other events would auto-populate into the calendar (IE: 14 days before send out fliers, 2 days after send out thank you emails, etc).
I got Python installed and the code does the basic job. He has the Python code link to a CSV file and I open up a DOS command prompt and enter the fields and everything populates fine.
Here is the basic CSV code:
"-14","Update calendar","12:00"
"-2","Send out email","12:00"
"2","Send out thank you email to attendees","12:00"
"4","Upload drunken pictures to MySpace","1:00"
Here is the Python code that I am pretty sure relats to the above CSV (again my apologies if I am missing important bits-I'd be happy to post more if needed):
# Two helper classes to parse CSV files.
class CalendarEvent:
def __init__(self):
self.interval_from_start = 0
self.description = ""
self.hour = 0
self.minute = 0
def __str__(self):
s = ""
for k,v in self.__dict__.iteritems():
s = s + "%s:\t%s\n" % (k,v)
return s + "\n"
class CalendarEventFactory:
def __init__(self, csv_file):
self.csv_file = csv_file
def loadEvents(self):
# List to hold events.
event_list = []
# Open the file
try:
f = open(self.csv_file, 'r')
except:
raise Exception, "Unable to open file %s" % self.csv_file
# Stuff it into the csv reader class
input_csv = csv.reader(f)
# For each item, create a CalendarEvent object
for item in input_csv:
hour, minute = item[2].split(':')
event = CalendarEvent()
event.interval_from_start = int(item[0])
event.description = item[1]
event.hour = int(hour)
event.minute = int(minute)
event_list.append(event)
# Close the file
f.close()
# Return the list
return event_list
# Helper function to list CSV files in a directory, without full path information
def list_csv_files(dirname):
files = []
csv_files = []
try:
files = os.listdir(dirname)
except:
raise Exception, "Unable to open directoy %s" % dirname
r = re.compile(".+\.csv")
for file in files:
if r.match(file):
csv_files.append(file)
return csv_files
Now the above code works fine, but it only allows me to input the description, date, and time of the event. I know that Google calendar is able to read more CSV information on an import:
From http://www.google.com/support/calendar/bin/answer.py?hl=en&answer=45656
To add more information to your events, simply add more headers. Possible headers include: Subject, Start Date, Start Time, End Date, End Time, All Day Event, Description, Location, and Private.
So this was my long winded way of asking my question:
How can I add all these other headers into the above python code? I have read a lot on the google pages, but I just don't know enough about this stuff to understand most of what is being talked about. I'm sure the answer is somewhere HERE, but I don't know where!
Thank you for your time and your patience!
Sincerely,
Joel