added excel->json recorder source generation script
This commit is contained in:
55
backend/tools/import_excel_recorder_list.py
Normal file
55
backend/tools/import_excel_recorder_list.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import json
|
||||
from pprint import pprint
|
||||
|
||||
import xlrd
|
||||
|
||||
MAX_CONSECUTIVE_EMPTY_ROWS_BEFORE_CANCEL = 5
|
||||
file_location = "/home/tobias/tmp/Hoersaal-Rec-Liste.xlsx"
|
||||
|
||||
wb = xlrd.open_workbook(file_location)
|
||||
sheet = wb.sheet_by_index(0)
|
||||
|
||||
headers = None
|
||||
recorders = []
|
||||
a_lot_of_empty_rows = False
|
||||
consecutive_empty_rows = 0
|
||||
ix = 0
|
||||
while not a_lot_of_empty_rows:
|
||||
try:
|
||||
vals = sheet.row_values(ix)
|
||||
except IndexError:
|
||||
break
|
||||
if len(set(vals)) == 1 and set(vals).pop() == '':
|
||||
consecutive_empty_rows += 1
|
||||
if consecutive_empty_rows > MAX_CONSECUTIVE_EMPTY_ROWS_BEFORE_CANCEL:
|
||||
a_lot_of_empty_rows = True
|
||||
else:
|
||||
consecutive_empty_rows = 0
|
||||
if len(set(vals)) > 5 and headers is None: # get table header
|
||||
headers = {ix: vals[ix] for ix in range(0, len(vals))}
|
||||
elif len(set(vals)) > 5: # regular rows
|
||||
recorders.append({headers[ix]: vals[ix] for ix in range(0, len(vals))})
|
||||
ix += 1
|
||||
if ix >= 100:
|
||||
a_lot_of_empty_rows = True
|
||||
|
||||
#pprint(recorders)
|
||||
print(len(recorders))
|
||||
|
||||
nicely_formatted_recorders = []
|
||||
for r in recorders:
|
||||
rec = {'name': r['Opencast / CM'],
|
||||
'building': r['Gebäude'],
|
||||
'room': r['Hörsaal'],
|
||||
'username': r['Benutzer'],
|
||||
'password': r['PW'],
|
||||
'ip': r['IP'],
|
||||
'mac': r['MAC'],
|
||||
'type': 'SMP 351' if 'SMP 351' in r['Rekorder-Typ'] else r['Rekorder-Typ'],
|
||||
'additional_camera': r['Zus. Kamera'] == 'Ja',
|
||||
'firmware_version': r['FW – Vers.'],
|
||||
'description': json.dumps(
|
||||
{'comment': r['Bemerkung'], 'network_port': r['Dosennummer'], 'rsync_name': r['Rsync-Name']})}
|
||||
nicely_formatted_recorders.append(rec)
|
||||
|
||||
print(json.dumps(nicely_formatted_recorders))
|
||||
57
backend/tools/simple_state_checker.py
Normal file
57
backend/tools/simple_state_checker.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from pprint import pprint
|
||||
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
from ics import Calendar
|
||||
|
||||
base_url = "https://opencast.bibliothek.kit.edu/recordings/calendars?agentid=CS+30.46+Chemie+Neuer+Hoersaal"
|
||||
base_url = "https://opencast.bibliothek.kit.edu"
|
||||
|
||||
session = requests.session()
|
||||
session.auth = HTTPBasicAuth("admin", "mz.paziuw!")
|
||||
|
||||
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()))
|
||||
Reference in New Issue
Block a user