|
#!/usr/bin/env python |
|
|
|
import sys, os |
|
import gflags |
|
import httplib2 |
|
import time |
|
|
|
from apiclient.discovery import build |
|
from oauth2client.file import Storage |
|
from oauth2client.client import OAuth2WebServerFlow |
|
from oauth2client.tools import run |
|
from rfc3339 import rfc3339 |
|
|
|
|
|
FLAGS = gflags.FLAGS |
|
|
|
FLOW = OAuth2WebServerFlow( |
|
client_id='YOUR_CLIENT_ID', |
|
client_secret='YOUR_CLIENT_SECRET', |
|
scope='https://www.googleapis.com/auth/calendar', |
|
user_agent='YOUR_APPLICATION_NAME/YOUR_APPLICATION_VERSION') |
|
|
|
storage = Storage('.git/calendar.dat') |
|
credentials = storage.get() |
|
if credentials is None or credentials.invalid == True: |
|
credentials = run(FLOW, storage) |
|
|
|
http = httplib2.Http() |
|
http = credentials.authorize(http) |
|
|
|
service = build(serviceName='calendar', version='v3', http=http, |
|
developerKey='YOUR_DEVELOPER_KEY') |
|
|
|
description = "%s\n" % os.popen("git whatchanged -1 --pretty=format:\"commiter: %cn <%ae>%ndate : %cd%n%s%n--------------------%n%b%n\"").read() |
|
summary = "[commit] %s" % os.popen("git log -1 --oneline").read() |
|
|
|
startTime = time.time() - 60 * 60 |
|
endTime = time.time() |
|
|
|
|
|
event = { |
|
'summary': summary, |
|
'description': description, |
|
'start' : { 'dateTime' : rfc3339(startTime) }, |
|
'end' : { 'dateTime' : rfc3339(endTime) } |
|
} |
|
|
|
created_event = service.events().insert(calendarId='YOUR_CALENDAR_ID', body=event).execute() |
|
|
|
print "Created Event: %s" % created_event['id'] |
genious