Skip to content

Instantly share code, notes, and snippets.

@jhwilson
Last active January 7, 2018 21:36
Show Gist options
  • Save jhwilson/09b3f43451d5f855fb5a to your computer and use it in GitHub Desktop.
Save jhwilson/09b3f43451d5f855fb5a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# org-mode-agenda-push-bullet.py
# Load org-mode agenda items, then push each item as a notification with PushBullet.
# Notication form:
# - Title: "Agenda Item: <CATEGORY>"
# - Note: "<TODO ITEM>"
from subprocess import Popen, PIPE
#from time import strptime
from pushbullet import PushBullet
def OrgModeAgenda(loadfile):
# Input: The loadfile that contains `org-agenda-files`
# Uses the org-mode elisp function `org-batch-agenda-csv` to output
# a machine readable list of agenda items. It then parses it and returns
# a list of Agenda items. Each Agenda item has two elements:
# - AgendaItems[i,0] is the ith element's category (file it came from)
# - AgendaItems[i,1] is the ith element's agenda item, modified by its
# other descriptors
AgendaItems = []
# The following taken from http://demonastery.org/2009/05/automatic-agenda-notification/
## This uses emacs to send us the agend items
Agenda = Popen("emacs --batch -l " + loadfile + " --eval '(org-batch-agenda-csv \"a\")'",shell=True,stdout=PIPE).communicate()[0].strip()
for line in Agenda.splitlines():
# What we know from http://orgmode.org/manual/Extracting-agenda-information.html
# about what each item is.
[category, head, ttype, todo, tags, date, time, extra, priorityl, priorityn, date2] = line.split(",")
# ===== PROCESSING Agenda information into notes to send ==== #
if priorityl:
head = "[" + priorityl + "] " + head
if ttype == "past-scheduled":
head = "LATE: " + head
if ttype == "deadline":
head = "Deadline " + date + ": " + head
if ttype == "scheduled":
head = "Scheduled " + date + ": " + head
if ttype == "upcoming-deadline":
head = "Upcoming " + date + ": " + head
if todo != "TODO":
head = head + " (" + todo + ")"
# ===== END OF PROCESSING ==== #
AgendaItems.append([category,head])
return AgendaItems
def main():
# ==== USER INPUT ==== #
# `api_key` is the api key supplied by PushBullet
# loadfile containes `org-agenda-files`
# - usually "~/.emacs" file OR
# - Aquamacs: "~/Library/Preferences/Aquamacs\ Emacs/customizations.el"
api_key = <INSERT API KEY>
loadfile = "~/.emacs"
# ==== END USER INPUT ==== #
pb = PushBullet(api_key)
AgendaItems = OrgModeAgenda(loadfile)
for item in AgendaItems:
## To test output:
# print "Agenda Item: "+item[0]
# print item[1]
success, push = pb.push_note("Agenda Item: "+item[0],item[1])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment