59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
from pprint import pprint
|
|
|
|
import requests
|
|
from requests.auth import HTTPBasicAuth
|
|
from ics import Calendar
|
|
|
|
from backend.config import Config
|
|
|
|
base_url = "https://opencast.bibliothek.kit.edu"
|
|
|
|
session = requests.session()
|
|
session.auth = HTTPBasicAuth(Config.OPENCAST_USER, Config.OPENCAST_PW)
|
|
|
|
config = {'service_urls': {}}
|
|
|
|
|
|
def get_service_url(service_type: str):
|
|
if service_type in config['service_urls']:
|
|
return config['service_urls'][service_type]
|
|
params = {'serviceType': service_type}
|
|
url = base_url + "/services/available.json"
|
|
res = session.get(url, params=params)
|
|
if res.ok:
|
|
service = res.json()["services"]["service"]
|
|
config["service_urls"][service_type] = service["host"] + \
|
|
service["path"]
|
|
return service["host"] +service["path"]
|
|
return None
|
|
|
|
|
|
def get_calender(rec_id):
|
|
params = {'agentid': rec_id}
|
|
url = get_service_url('org.opencastproject.scheduler') + "/calendars"
|
|
print(url)
|
|
res = session.get(url, params=params)
|
|
if res.ok:
|
|
return Calendar(res.text)
|
|
|
|
|
|
def get_capture_agents():
|
|
url = get_service_url("org.opencastproject.capture.admin") + "/agents.json"
|
|
res = session.get(url)
|
|
if res.ok:
|
|
return res.json()["agents"]["agent"]
|
|
|
|
agents = get_capture_agents()
|
|
for a in agents:
|
|
print(a['name'])
|
|
print(a['state'])
|
|
if a['state'] == "capturing":
|
|
c = get_calender(a['name'])
|
|
print(list(c.timeline.now()))
|
|
exit()
|
|
|
|
c = get_calender('CS 30.46 Chemie Neuer Hoersaal')
|
|
print(c.events)
|
|
print(list(c.timeline)) # chronological order
|
|
print(list(c.timeline.now()))
|