Last active
August 29, 2015 14:15
-
-
Save matbor/17e69db89855a953bffc to your computer and use it in GitHub Desktop.
A quick python script using Sickbeard api to get what TV has downloaded today and format for mqttwarn (for mqtt message/topic). I run this via cron at 7pm (when i sit down for the night, hopefully!) and i can quickly see what to watch. If you are very clever you could have this delivered to your phone when you turn your TV on at night. (aka open…
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 | |
# -*- coding: utf-8 -*- | |
import json | |
import urllib2 | |
import time | |
import datetime | |
import paho.mqtt.publish as publish | |
# Show's the last 10 episodes that have been downloaded using sickbeard recently | |
# working example; http://localhost:9002/api/xxxxxxxxxxxxxxxxxxxxxxxxxxx/?cmd=history&limit=10&type=downloaded | |
# Edit Settings | |
ip = "192.168.4.22:8081" | |
api = "xxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
cmd = "history&limit=10&type=downloaded" | |
#mqtt broker settings | |
hostname = "127.0.0.1" | |
topic = "/house/messages" | |
#End Settings | |
# make url | |
sb = "http://%s/api/%s/?cmd=%s" % (ip, api, cmd) | |
response = urllib2.urlopen(sb) | |
jsonResponse = json.loads(response.read()) | |
jsonData = jsonResponse["data"] | |
listofshows = "" | |
for item in jsonData: | |
show_name = item.get("show_name") | |
date_object = datetime.datetime.strptime(item.get("date"), '%Y-%m-%d %H:%M') | |
if date_object.timetuple().tm_mday == datetime.date.today().day: | |
#print("%s" % (show_name)) | |
listofshows = show_name + "\n" + listofshows #add one per line | |
print(listofshows) | |
#format for mqttwarn message delivery | |
msgjson = json.dumps(dict( | |
lvl = "4", | |
sub = "NEW TV to Catch up on tonight", | |
txt = listofshows[:-1].encode('utf8'), | |
delay = "20000", | |
img = "info.png", | |
url = "http://" + ip | |
)) | |
#print("JSON msg: %s" % (msgjson)) | |
publish.single(topic, msgjson, hostname=hostname) |
mqttwarn.ini
settings;
[messages]
topic = /house/messages
targets = log:debug,pushover:message
title = {sub}
format = {txt}
also compatible with my mqtt2chrome notifications popups with this setup.
BTW - the wife loves this new 'feature'. Every time she fires up XBMC she gets the little notification listing the shows are have downloaded. Cheers!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have removed the code for the other scenes as it was a bit too much.