Created
December 18, 2013 21:22
-
-
Save fcrespo82/8030079 to your computer and use it in GitHub Desktop.
Send Due tasks from any computer with Python
This file contains hidden or 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/env python | |
import pushover | |
import sys | |
import datetime | |
import dateutil.parser | |
import urllib | |
DUE_URL = "due://x-callback-url/add?title={0}&duedate={1}&timezone=GMT" | |
if __name__ == '__main__': | |
if len(sys.argv) >= 3: | |
seconds = (dateutil.parser.parse(sys.argv[2]) - datetime.datetime(1970, 1, 1)).total_seconds() | |
URL = DUE_URL.format(urllib.quote(sys.argv[1]), seconds) | |
pushover.sendPush(sys.argv[1], "Due", URL, "") | |
else: | |
print("usage: {0} \"message\" \"datetime\"".format(sys.argv[0].split("/")[-1])) |
This file contains hidden or 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
{ | |
"USER_TOKEN": "SDLFJKBGLSDFKJGSDFKLJGBDFKBGJD", | |
"APP_TOKEN": "ASDKLBGJLDFKBGJDFLGJKGLSJKFGKJ" | |
} |
This file contains hidden or 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 | |
import requests | |
import sys | |
import json | |
import os | |
HEADERS = { "Content-type": "application/x-www-form-urlencoded" } | |
USER_INFO = json.load(open("/".join([os.path.dirname(os.path.realpath(__file__)),"pushover.json"]))) | |
#sendPush('How to open Launch Center Pro from pushover', 'Pushover test', 'launchpro://', 'Open Launch Center Pro') | |
def sendPush(message, title, url, url_title): | |
parameters = { u'token': USER_INFO["APP_TOKEN"], | |
u'user': USER_INFO["USER_TOKEN"], | |
u'message': message, | |
u'title': title, | |
u'url': url, | |
u'url_title': url_title } | |
r = requests.post(u'https://api.pushover.net/1/messages.json', data=parameters, headers=HEADERS) | |
print(r.headers) | |
if r.status_code == requests.codes.ok: | |
print(u'Push sent successfully') | |
else: | |
print(u'Error sending push') | |
if __name__ == '__main__': | |
if len(sys.argv) >= 2: | |
message = message_title = url = url_title = '' | |
if len(sys.argv) >= 2: message = sys.argv[1] | |
if len(sys.argv) >= 3: message_title = sys.argv[2] | |
if len(sys.argv) >= 4: url = sys.argv[3] | |
if len(sys.argv) >= 5: url_title = sys.argv[4] | |
sendPush(message, message_title, url, url_title) | |
else: | |
print("usage: {0} \"message\" \"title\" \"url\" \"url title\"".format(sys.argv[0].split("/")[-1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment