This article will show you how to utilize Emacs org-mode, python, a Nokia mobile (others may work too), and an SMS gateway like Clickatell, in order to receive a daily agenda that fits nicely into the phones calendar by using the vCalendar format. Yes that’s a fairly specialized combination, but hopefully will be useful to someone. I’m sure it’s possible to do the same using bluetooth instead of and SMS gateway, and I may update this to reflect that at some stage..
Firstly, you will need org-mode set up and being utilized. Hopefully within it you will have something like:
* Write some code <2009-05-02 Saturday 3:00PM> * Write some more code <2009-05-02 Saturday 8:00PM>
The idea is simple, we want some way of taking these headings, and turning them into vCalendar strings that can be sent to your phone.
This first script is what I use to do just that:
#!/usr/bin/env python from subprocess import Popen,PIPE; from time import strftime, strptime; from sendsms import sendsms; dateformat = "%Y%m%dT%H%M%S"; vcals = ; output = Popen("/usr/bin/emacs -batch -eval '(org-batch-agenda-csv \"a\" org-agenda-ndays 1 org-agenda-show-all-dates t org-agenda-files `(,(expand-file-name \"/full/path/to/your/org/file\")))' 2>/dev/null", shell=True, stdout=PIPE).communicate().strip(); for line in output.splitlines(): [category, head, type, todo, tags, date, time, extra, priorityl, priorityn, date2] = line.split(","); if type and time: if type == "scheduled": head = "SCHEDULED, " + head; if type == "deadline": head = "DEADLINE, " + head; timestamp = strptime(date + " " + time, "%Y-%m-%d %H%M"); vcals.append("BEGIN:VCALENDAR\nVERSION:1.0\nBEGIN:VEVENT\nCATEGORIES:APPOINTMENT\nDTSTART:" + strftime(dateformat, timestamp) + "\nDTEND:" + strftime(dateformat, timestamp) + "\nSUMMARY:" + head + "\nDESCRIPTION:" + head + "\nEND:VEVENT\nEND:VCALENDAR"); for vcal in vcals: sendsms(vcal, "yourphonenumberhere", "SMS_NOKIA_VCAL");
And here is the helper script to send sms through the Clickatell gateway:
#!/usr/bin/env python # Script to send SMS via clickatell import urllib, urllib2; username = "put your Clickatell username here"; password = "put your Clickatell password here"; api_id = "put your Clickatell api id here"; def sendsms(data, number = "yournumberhere", type = "SMS_TEXT"): request = "https://api.clickatell.com/http/sendmsg?user=" + username + "&password=" + password + "&api_id=" + api_id + "&to=" + number + "&msg_type=" + type + "&text=" + urllib.quote_plus(data); f = urllib2.urlopen(request); print f.read();
As long as this is in the same directory as
agenda.py then it should import fine, otherwise you will want to move it into your Python PATH.
Now all you need to do is add something like this to your crontab (use
15 7 * * * /path/to/agenda.py
Make sure to replace everything in the scripts where necessary.
Congratulations! Your PC should be ready to send your daily appointments to your phone at 7:15 every morning :)