46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
import requests
|
|
import json
|
|
|
|
dispatcher_url = "https://dispatcher-api.psi.ch/sf"
|
|
|
|
def get_dispatcher(path):
|
|
response = requests.get(url=dispatcher_url+path)
|
|
if response.status_code != 200:
|
|
raise Exception(response.text)
|
|
return json.loads(response.text)
|
|
|
|
def post_dispatcher(path, data):
|
|
response = requests.post(url=dispatcher_url+path, json=data)
|
|
if response.status_code != 200:
|
|
raise Exception(response.text)
|
|
return json.loads(response.text)
|
|
|
|
|
|
def get_dispatcher_info(regex):
|
|
return post_dispatcher("/channels/live",{"regex": regex})[0]
|
|
|
|
def get_dispatcher_channels(regex):
|
|
return get_dispatcher_info(regex)["channels"]
|
|
|
|
def get_dispatcher_channel_info(channel_name):
|
|
return get_dispatcher_info(channel_name)["channels"][0]
|
|
|
|
def get_dispatcher_channel_modulo(channel_name):
|
|
return get_dispatcher_channel_info(channel_name)
|
|
|
|
def get_dispatcher_channel_modulo(channel_name):
|
|
return get_dispatcher_channel_info(channel_name).get("modulo", 1)
|
|
|
|
def get_dispatcher_channel_offset(channel_name):
|
|
return get_dispatcher_channel_info(channel_name).get("offset", 0)
|
|
|
|
def get_dispatcher_stream(channel_names):
|
|
channels = []
|
|
for channel_name in channel_names:
|
|
#info = get_dispatcher_channel_info(channel_name)
|
|
#channels.append({"name":channel_name,"backend":"sf-databuffer","modulo":info.get("modulo", 1), "offset":info.get("offset", 0)})
|
|
channels.append({"name":channel_name,"backend":"sf-databuffer","modulo":None, "offset":None})
|
|
return post_dispatcher("/stream",{"channels": channels})
|
|
|
|
|