Last active
August 24, 2016 05:53
-
-
Save htpc-helper/777b8516a5d9cf59e38bc1d5ab031a3f to your computer and use it in GitHub Desktop.
Class for obtaining list of upcoming, completed, and current recordings from TVHeadend web api
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 urllib2, json | |
class TVHeadend: | |
def __init__(self, host, port): | |
self.url = 'http://' + host + ':' + port | |
def GetRunning(self): | |
url = '/api/dvr/entry/grid_upcoming' | |
data = self.__RequestData(url)['entries'] | |
return self.__ProcessData(data, 'Running') | |
def GetUpcoming(self): | |
url = '/api/dvr/entry/grid_upcoming' | |
data = self.__RequestData(url)['entries'] | |
return self.__ProcessData(data, 'Upcoming') | |
def GetCompleted(self): | |
url = '/api/dvr/entry/grid_finished' | |
data = self.__RequestData(url)['entries'] | |
return self.__ProcessData(data, 'Completed') | |
def __ProcessData(self, data, method): | |
if data == None: return [] | |
return_list = [] | |
for item in data: | |
if method == 'Upcoming' and item['status'] != 'Running': | |
return_list.append(item) | |
if method == 'Running' and item['status'] == 'Running': | |
return_list.append(item) | |
if method == 'Completed': | |
return_list = data | |
break | |
return_list = sorted(return_list, key=lambda k: k['start']) | |
return return_list | |
def __RequestData(self, url): | |
url = self.url + url | |
response = urllib2.urlopen(url) | |
data = json.loads(response.read()) | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment