2013年5月29日 星期三

Google Data Python Library + 寫入Event至Calendar

先確定已經安裝好python及Google Data Python Library(可參考):

import datetime
import atom
import gdata.calendar.service
from gdata.calendar import Who, Where, When
from gdata.calendar import SendEventNotifications


start = datetime.datetime.now().isoformat()

entry = gdata.calendar.CalendarEventEntry()
entry.send_event_notifications = SendEventNotifications(value='true')

titleText = 'event' + start
entry.title = atom.Title(text = titleText)

contextText = 'some event etc...\n' + start
entry.content = atom.Content(text = contextText)

entry.send_event_notifications = atom.Entry(text = 'true') #<<<<<<<<<<<<<<<<<
entry.when.append(When(start_time=start))
entry.where.append(Where(value_string='somewhere'))
entry.who.append(Who(email = 'INVENTEE@gmail.com'))

client = gdata.calendar.service.CalendarService(email='INVENTER@gmail.com', password='YOURPW')

client.ProgrammaticLogin()
event = client.InsertEvent(entry,'http://www.google.com/calendar/feeds/default/private/full')

#

補記:將這個python程式稍加修改後,即可應用在前兩篇 Raspberry Pi + PIR Sensor (紅外線動作感測器)的範例中。其實就能達成紅外線感應偵測到人或動物時,即能在Google Calendar紀錄事件,並且還可以利用Google Calendar簡訊通知至手機。

##

沒有留言: