Created
December 14, 2011 10:52
-
-
Save metachu/1476107 to your computer and use it in GitHub Desktop.
Sms with google calendar
This file contains 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/bin/python | |
#requires pip install google-api-python-client | |
#requires pip install gdata | |
import sys | |
import os | |
import gdata | |
import time | |
import gdata.calendar.service | |
import gdata.calendar | |
username="[email protected]" | |
password="PASSWORD" | |
calendar_service = gdata.calendar.service.CalendarService(username | |
, password | |
, "gcalpy-v1") | |
calendar_service.ProgrammaticLogin() | |
def sms(title, | |
content, | |
start_time=None, end_time=None): | |
global calendar_service | |
event = gdata.calendar.CalendarEventEntry() | |
event.title = gdata.atom.Title(text=title) | |
event.content = gdata.atom.Content(text=content) | |
reminder = gdata.calendar.Reminder(minutes=1) | |
reminder.method = 'sms' | |
if start_time is None: | |
# Use current time for the start_time and have the event last 1 hour | |
start_time = time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime(time.time()+120)) | |
end_time = time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime(time.time() + 3600)) | |
when = gdata.calendar.When(start_time=start_time, end_time=end_time) | |
when.reminder.append(reminder) | |
event.when.append(when) | |
new_event = calendar_service.InsertEvent(event, '/calendar/feeds/default/private/full') | |
return new_event | |
if len(sys.argv) < 2: | |
sys.exit('Usage: sms message\n Message will appear in 1 minute') | |
else: | |
message = " ".join(sys.argv[1:]) | |
sms(message,"sms") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment