CC-2097: Show-recorder: Use RabbitMQ, api_client, and the structure of pypofetch
using api client now
This commit is contained in:
parent
9546d9670e
commit
c727c338af
10 changed files with 334 additions and 274 deletions
|
@ -13,6 +13,7 @@
|
|||
import sys
|
||||
import time
|
||||
import urllib
|
||||
import urllib2
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
|
@ -90,6 +91,12 @@ class ApiClientInterface:
|
|||
# You will be able to use this data in update_start_playing
|
||||
def get_liquidsoap_data(self, pkey, schedule):
|
||||
pass
|
||||
|
||||
def get_shows_to_record(self):
|
||||
pass
|
||||
|
||||
def upload_recorded_show(self):
|
||||
pass
|
||||
|
||||
# Put here whatever tests you want to run to make sure your API is working
|
||||
def test(self):
|
||||
|
@ -225,24 +232,6 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
except Exception, e:
|
||||
print e
|
||||
|
||||
#schedule = response["playlists"]
|
||||
#scheduleKeys = sorted(schedule.iterkeys())
|
||||
#
|
||||
## Remove all playlists that have passed current time
|
||||
#try:
|
||||
# tnow = time.localtime(time.time())
|
||||
# str_tnow_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tnow[0], tnow[1], tnow[2], tnow[3], tnow[4], tnow[5])
|
||||
# toRemove = []
|
||||
# for pkey in scheduleKeys:
|
||||
# if (str_tnow_s > schedule[pkey]['end']):
|
||||
# toRemove.append(pkey)
|
||||
# else:
|
||||
# break
|
||||
# for index in toRemove:
|
||||
# del schedule[index]
|
||||
#except Exception, e:
|
||||
#response["playlists"] = schedule
|
||||
|
||||
return status, response
|
||||
|
||||
|
||||
|
@ -316,6 +305,42 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
except Exception, e:
|
||||
data["schedule_id"] = 0
|
||||
return data
|
||||
|
||||
def get_shows_to_record(self):
|
||||
logger = logging.getLogger()
|
||||
response = ''
|
||||
try:
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"]
|
||||
#logger.debug(url)
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
logger.debug(url)
|
||||
response = urllib.urlopen(url)
|
||||
response = json.loads(response.read())
|
||||
logger.info("shows %s", response)
|
||||
|
||||
except Exception, e:
|
||||
logger.error("Exception: %s", e)
|
||||
|
||||
return response[u'shows']
|
||||
|
||||
def upload_recorded_show(self, data, headers):
|
||||
logger = logging.getLogger()
|
||||
response = ''
|
||||
try:
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
|
||||
#logger.debug(url)
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
logger.debug(url)
|
||||
|
||||
request = urllib2.Request(url, data, headers)
|
||||
response = urllib2.urlopen(request).read().strip()
|
||||
|
||||
logger.info("uploaded show result %s", response)
|
||||
|
||||
except Exception, e:
|
||||
logger.error("Exception: %s", e)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue