Created
March 15, 2011 13:14
-
-
Save mizchi/870700 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python | |
| # encoding:utf-8 | |
| import gdata.calendar | |
| from xml.etree import ElementTree # for Python 2.5 users | |
| import gdata.calendar.service | |
| import gdata.service | |
| import atom.service | |
| import gdata.calendar | |
| import atom | |
| import time | |
| import datetime | |
| jinka = 'fgrtdnibb5uii5lm8d1m3ack2o@group.calendar.google.com' | |
| client = gdata.calendar.service.CalendarService() | |
| client.email = '' | |
| client.password = '' | |
| client.source = 'Google-Calendar_Python_Sample-1.0' | |
| client.ProgrammaticLogin() | |
| def get_time(d,num,year=2011,month=4): | |
| day = {"mon":4,"tue":5,"wed":6,"thr":7,"fri":8,"":9} | |
| jugyo = {"1":datetime.datetime(year, month, day[d], 9,0), | |
| "2":datetime.datetime(year, month, day[d], 10,40), | |
| "3":datetime.datetime(year, month, day[d], 13,0), | |
| "4":datetime.datetime(year, month, day[d], 14,45), | |
| "5":datetime.datetime(year, month, day[d], 16,30), | |
| "6":datetime.datetime(year, month, day[d], 18,15) | |
| } | |
| return jugyo[str(num)] | |
| def insert_event(calendar_service, | |
| title='One-time Tennis with Beth', | |
| content='Meet for a quick lesson', | |
| where='On the courts', | |
| start_time=None, | |
| end_time=None, | |
| cal_id='default', | |
| recurrence=None): | |
| event = gdata.calendar.CalendarEventEntry() | |
| event.title = atom.Title(text=title) | |
| event.content = atom.Content(text=content) | |
| event.where.append(gdata.calendar.Where(value_string=where)) | |
| event.timezone = gdata.calendar.Timezone(value='GMT+09:00') | |
| start_time -= datetime.timedelta(hours=9) | |
| # if recurrence: | |
| # recurrence_data = ( | |
| # 'DTSTART;VALUE=DATE:20110402\r\n' | |
| # + 'DTEND;VALUE=DATE:20110802\r\n' | |
| # + 'RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20110904\r\n') | |
| # event.recurrence = gdata.calendar.Recurrence(text=recurrence_data) | |
| start = start_time.strftime("%Y-%m-%dT%H:%M:%S.000Z") | |
| end = (start_time + datetime.timedelta(hours=1,minutes=30)).strftime("%Y-%m-%dT%H:%M:%S.000Z") | |
| event.when.append(gdata.calendar.When( | |
| start_time=start, | |
| end_time=end)) | |
| print start | |
| print end | |
| new_event = calendar_service.InsertEvent(event, '/calendar/feeds/%s/private/full'%cal_id) | |
| print 'New single event inserted: %s' % (new_event.id.text,) | |
| print '\tEvent edit URL: %s' % (new_event.GetEditLink().href,) | |
| print '\tEvent HTML URL: %s' % (new_event.GetHtmlLink().href,) | |
| return new_event | |
| # feed = client.GetCalendarEventFeed("/calendar/feeds/%s/private/full" % jinka) | |
| # for event in feed.entry: | |
| # print event.title.text | |
| insert_event(client, | |
| cal_id=jinka, | |
| title="内分泌学", | |
| content='山内兄人', | |
| where='tokorozawa', | |
| start_time = get_time('mon',1) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment