mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-05-27 14:12:34 +02:00
2021-11-09 Fred Gleason <fredg@paravelsystems.com>
* Added a 'ListLog()' method to the 'rivwebpyapi'. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
parent
cd7ed74202
commit
48bd62d6df
@ -22596,3 +22596,5 @@
|
||||
2021-11-08 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Added a 'ListGroup()' method to the 'rivwebpyapi' API.
|
||||
* Added a 'ListGroups()' method to the 'rivwebpyapi' API.
|
||||
2021-11-09 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Added a 'ListLog()' method to the 'rivwebpyapi'.
|
||||
|
@ -27,7 +27,7 @@ import xml.sax
|
||||
class RivWebPyApi_ListHandler(ContentHandler):
|
||||
def __init__(self,base_tag,fields):
|
||||
self.__output=[]
|
||||
self.__svc={}
|
||||
self.__record={}
|
||||
self.__base_tag=base_tag
|
||||
self.__fields=fields;
|
||||
self.__field=''
|
||||
@ -37,32 +37,53 @@ class RivWebPyApi_ListHandler(ContentHandler):
|
||||
for f in self.__fields.keys():
|
||||
d[f]=d[f].strip()
|
||||
if(self.__fields[f]=='boolean'):
|
||||
d[f]=d[f]!='0'
|
||||
d[f]=self.__fromBoolean(d[f])
|
||||
elif(self.__fields[f]=='datetime'):
|
||||
d[f]=self.__parseDatetime(d[f])
|
||||
d[f]=self.__fromDatetime(d[f])
|
||||
elif(self.__fields[f]=='date'):
|
||||
d[f]=self.__parseDate(d[f])
|
||||
d[f]=self.__fromDate(d[f])
|
||||
elif(self.__fields[f]=='integer'):
|
||||
d[f]=int(d[f])
|
||||
d[f]=self.__fromInteger(d[f])
|
||||
elif(self.__fields[f]=='time'):
|
||||
d[f]=self.__fromTime(d[f])
|
||||
return self.__output
|
||||
|
||||
def startElement(self,tag,attrs):
|
||||
if(tag==self.__base_tag): # Create new (empty) record
|
||||
self.__svc={}
|
||||
self.__record={}
|
||||
for f in self.__fields.keys():
|
||||
self.__svc[f]=''
|
||||
self.__record[f]=''
|
||||
self.__field=tag
|
||||
|
||||
def endElement(self,tag):
|
||||
if(tag==self.__base_tag): # Add completed record to output
|
||||
self.__output.append(self.__svc)
|
||||
self.__output.append(self.__record)
|
||||
self.__field=''
|
||||
|
||||
def characters(self,content):
|
||||
if(self.__field in self.__fields.keys()): # Add content to field
|
||||
self.__svc[self.__field]=self.__svc[self.__field]+content
|
||||
self.__record[self.__field]=self.__record[self.__field]+content
|
||||
|
||||
def __parseDatetime(self,str):
|
||||
def __fromBoolean(self,str):
|
||||
if(not str):
|
||||
return None
|
||||
if((str=='1')or(str.lower()=='true')):
|
||||
return True
|
||||
if((str=='0')or(str.lower()=='false')):
|
||||
return False
|
||||
raise ValueError('invalid boolean value')
|
||||
|
||||
def __fromDate(self,str):
|
||||
if(not str):
|
||||
return None
|
||||
f0=str.split('-')
|
||||
if(len(f0)!=3):
|
||||
raise(ValueError('invalid date string'))
|
||||
return datetime.date(year=int(f0[0]),
|
||||
month=int(f0[1]),
|
||||
day=int(f0[2]));
|
||||
|
||||
def __fromDatetime(self,str):
|
||||
if(not str):
|
||||
return None
|
||||
f0=str.split('T')
|
||||
@ -88,15 +109,66 @@ class RivWebPyApi_ListHandler(ContentHandler):
|
||||
second=int(time_parts[2]),
|
||||
tzinfo=datetime.timezone(offset));
|
||||
|
||||
def __parseDate(self,str):
|
||||
def __fromInteger(self,str):
|
||||
if(not str):
|
||||
return None
|
||||
f0=str.split('-')
|
||||
if(len(f0)!=3):
|
||||
raise(ValueError('invalid date string'))
|
||||
return datetime.date(year=int(f0[0]),
|
||||
month=int(f0[1]),
|
||||
day=int(f0[2]));
|
||||
return int(str)
|
||||
|
||||
def __fromTime(self,str):
|
||||
if(not str):
|
||||
return None
|
||||
|
||||
#
|
||||
# Split time from timezone fields
|
||||
#
|
||||
timestr=''
|
||||
zonestr=''
|
||||
if('+' in str):
|
||||
f0=str.split('+')
|
||||
timestr=f0[0]
|
||||
zonestr=f0[1]
|
||||
elif('-' in str):
|
||||
f0=str.split('-')
|
||||
timestr=f0[0]
|
||||
zonestr=f0[1]
|
||||
else:
|
||||
timestr=str
|
||||
|
||||
#
|
||||
# Calculate time part
|
||||
#
|
||||
time_parts=timestr.split(':')
|
||||
if(len(time_parts)!=3):
|
||||
raise ValueError('invalid time string')
|
||||
msecs=0
|
||||
if('.' in time_parts[2]):
|
||||
f0=time_parts[2].split('.')
|
||||
msecs=int(f0[1])
|
||||
time_parts[2]=f0[0]
|
||||
|
||||
#
|
||||
# Calculate timezone offset
|
||||
#
|
||||
offset_minutes=0
|
||||
if(zonestr):
|
||||
offset_minutes=60*int(zonestr[0:2])+int(timestr[3:5])
|
||||
|
||||
#
|
||||
# Put it all together
|
||||
#
|
||||
if(zonestr):
|
||||
offset=timedelta(minutes=offset_minutes)
|
||||
if('-' in str):
|
||||
offset=-offset
|
||||
return datetime.time(hour=int(time_parts[0]),
|
||||
minute=int(time_parts[1]),
|
||||
second=int(time_parts[2]),
|
||||
microsecond=1000*msecs,
|
||||
tzinfo=datetime.timezone(offset))
|
||||
return datetime.time(hour=int(time_parts[0]),
|
||||
minute=int(time_parts[1]),
|
||||
second=int(time_parts[2]),
|
||||
microsecond=1000*msecs)
|
||||
|
||||
class rivwebpyapi(object):
|
||||
"""
|
||||
@ -211,6 +283,109 @@ class rivwebpyapi(object):
|
||||
|
||||
return handler.output()
|
||||
|
||||
def ListLog(self,log_name):
|
||||
"""
|
||||
Returns a list of Rivendell logs (dictionary).
|
||||
|
||||
Takes the following argument:
|
||||
|
||||
log_name - Return the specified log. (string)
|
||||
"""
|
||||
|
||||
#
|
||||
# Build the WebAPI arguments
|
||||
#
|
||||
postdata={
|
||||
'COMMAND': '22',
|
||||
'LOGIN_NAME': self.__connection_username,
|
||||
'PASSWORD': self.__connection_password,
|
||||
'NAME': log_name
|
||||
}
|
||||
|
||||
#
|
||||
# Fetch the XML
|
||||
#
|
||||
r=requests.post(self.__connection_url,data=postdata)
|
||||
if(r.status_code!=requests.codes.ok):
|
||||
r.raise_for_status()
|
||||
|
||||
#
|
||||
# Generate the output dictionary
|
||||
#
|
||||
fields={
|
||||
'line': 'integer',
|
||||
'id': 'integer',
|
||||
'type': 'string',
|
||||
'cartType': 'string',
|
||||
'cartNumber': 'integer',
|
||||
'cutNumber': 'integer',
|
||||
'groupName': 'string',
|
||||
'groupColor': 'string',
|
||||
'title': 'string',
|
||||
'artist': 'string',
|
||||
'publisher': 'string',
|
||||
'composer': 'string',
|
||||
'album': 'string',
|
||||
'label': 'string',
|
||||
'year': 'integer',
|
||||
'client': 'string',
|
||||
'agency': 'string',
|
||||
'conductor': 'string',
|
||||
'userDefined': 'string',
|
||||
'usageCode': 'integer',
|
||||
'enforceLength': 'boolean',
|
||||
'forcedLength': 'string',
|
||||
'evergreen': 'boolean',
|
||||
'source': 'string',
|
||||
'timeType': 'string',
|
||||
'startTime': 'time',
|
||||
'transitionType': 'string',
|
||||
'cutQuantity': 'integer',
|
||||
'lastCutPlayed': 'integer',
|
||||
'markerComment': 'string',
|
||||
'markerLabel': 'string',
|
||||
'description': 'string',
|
||||
'isrc': 'string',
|
||||
'isci': 'string',
|
||||
'recordingMbId': 'string',
|
||||
'releaseMbId': 'string',
|
||||
'originUser': 'string',
|
||||
'originDateTime': 'datetime',
|
||||
#'startPoint': 'integer',
|
||||
#'endPoint': 'integer',
|
||||
#'segueStartPoint': 'integer',
|
||||
#'segueEndPoint': 'integer',
|
||||
'segueGain': 'integer',
|
||||
#'fadeupPoint': 'integer',
|
||||
'fadeupGain': 'integer',
|
||||
#'fadedownPoint': 'integer',
|
||||
'fadedownGain': 'integer',
|
||||
'duckUpGain': 'integer',
|
||||
'duckDownGain': 'integer',
|
||||
'talkStartPoint': 'integer',
|
||||
'talkEndPoint': 'integer',
|
||||
'hookMode': 'boolean',
|
||||
'hookStartPoint': 'integer',
|
||||
'hookEndPoint': 'integer',
|
||||
'eventLength': 'integer',
|
||||
'linkEventName': 'string',
|
||||
'linkStartTime': 'time',
|
||||
'linkStartSlop': 'integer',
|
||||
'linkEndSlop': 'integer',
|
||||
'linkId': 'integer',
|
||||
'linkEmbedded': 'boolean',
|
||||
'extStartTime': 'time',
|
||||
'extLength': 'integer',
|
||||
'extCartName': 'string',
|
||||
'extData': 'string',
|
||||
'extEventId': 'integer',
|
||||
'extAnncType': 'string'
|
||||
}
|
||||
handler=RivWebPyApi_ListHandler(base_tag='logLine',fields=fields)
|
||||
xml.sax.parseString(r.text,handler)
|
||||
|
||||
return handler.output()
|
||||
|
||||
def ListLogs(self,service_name='',log_name='',trackable=False,
|
||||
filter_string='',recent=False):
|
||||
"""
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
EXTRA_DIST = list_group.py\
|
||||
list_groups.py\
|
||||
list_log.py\
|
||||
list_logs.py\
|
||||
list_services.py
|
||||
|
||||
|
139
apis/rivwebpyapi/tests/list_log.py
Executable file
139
apis/rivwebpyapi/tests/list_log.py
Executable file
@ -0,0 +1,139 @@
|
||||
#!%PYTHON_BANGPATH%
|
||||
|
||||
# list_log.py
|
||||
#
|
||||
# RivWebPyApi test script for Rivendell
|
||||
#
|
||||
# Test the ListLog Web API call
|
||||
#
|
||||
# (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
|
||||
import getpass
|
||||
import rivwebpyapi
|
||||
import sys
|
||||
|
||||
url='';
|
||||
username=''
|
||||
password=''
|
||||
service_name=''
|
||||
log_name=''
|
||||
trackable=False
|
||||
filter_string=''
|
||||
recent=False
|
||||
|
||||
#
|
||||
# Get login parameters
|
||||
#
|
||||
usage='list_log --url=<rd-url> --username=<rd-username> [--password=<passwd>] [--log-name=<name>]'
|
||||
for arg in sys.argv:
|
||||
f0=arg.split('=')
|
||||
if(len(f0)==2):
|
||||
if(f0[0]=='--url'):
|
||||
url=f0[1]
|
||||
if(f0[0]=='--username'):
|
||||
username=f0[1]
|
||||
if(f0[0]=='--password'):
|
||||
password=f0[1]
|
||||
if(f0[0]=='--log-name'):
|
||||
log_name=f0[1]
|
||||
if(not password):
|
||||
password=getpass.getpass()
|
||||
if((not url)or(not username)):
|
||||
print(usage)
|
||||
sys.exit(1)
|
||||
|
||||
#
|
||||
# Get the log list
|
||||
#
|
||||
webapi=rivwebpyapi.rivwebpyapi(url=url,username=username,password=password)
|
||||
loglines=webapi.ListLog(log_name=log_name)
|
||||
|
||||
#
|
||||
# Display the log list
|
||||
#
|
||||
for ll in loglines:
|
||||
print('line: '+str(ll['line']))
|
||||
print('id: '+str(ll['id']))
|
||||
print('type: '+str(ll['type']))
|
||||
print('cartType: '+str(ll['cartType']))
|
||||
print('cartNumber: '+str(ll['cartNumber']))
|
||||
print('cutNumber: '+str(ll['cutNumber']))
|
||||
print('groupName: '+str(ll['groupName']))
|
||||
print('groupColor: '+str(ll['groupColor']))
|
||||
print('title: '+str(ll['title']))
|
||||
print('artist: '+str(ll['artist']))
|
||||
print('publisher: '+str(ll['publisher']))
|
||||
print('composer: '+str(ll['composer']))
|
||||
print('album: '+str(ll['album']))
|
||||
print('label: '+str(ll['label']))
|
||||
print('year: '+str(ll['year']))
|
||||
print('client: '+str(ll['client']))
|
||||
print('agency: '+str(ll['agency']))
|
||||
print('conductor: '+str(ll['conductor']))
|
||||
print('userDefined: '+str(ll['userDefined']))
|
||||
print('usageCode: '+str(ll['usageCode']))
|
||||
print('enforceLength: '+str(ll['enforceLength']))
|
||||
print('forcedLength: '+str(ll['forcedLength']))
|
||||
print('evergreen: '+str(ll['evergreen']))
|
||||
print('source: '+str(ll['source']))
|
||||
print('timeType: '+str(ll['timeType']))
|
||||
print('startTime: '+str(ll['startTime']))
|
||||
print('transitionType: '+str(ll['transitionType']))
|
||||
print('cutQuantity: '+str(ll['cutQuantity']))
|
||||
print('lastCutPlayed: '+str(ll['lastCutPlayed']))
|
||||
print('markerComment: '+str(ll['markerComment']))
|
||||
print('markerLabel: '+str(ll['markerComment']))
|
||||
print('description: '+str(ll['description']))
|
||||
print('isrc: '+str(ll['isrc']))
|
||||
print('isci: '+str(ll['isci']))
|
||||
print('recordingMbId: '+str(ll['recordingMbId']))
|
||||
print('releaseMbId: '+str(ll['releaseMbId']))
|
||||
print('originUser: '+str(ll['originUser']))
|
||||
print('originDateTime: '+str(ll['originDateTime']))
|
||||
#print('startPoint: '+str(ll['startPoint']))
|
||||
#print('endPoint: '+str(ll['endPoint']))
|
||||
#print('segueStartPoint: '+str(ll['segueStartPoint']))
|
||||
#print('segueEndPoint: '+str(ll['segueEndPoint']))
|
||||
print('segueGain: '+str(ll['segueGain']))
|
||||
#print('fadeupPoint: '+str(ll['fadeupPoint']))
|
||||
#print('fadeupGain: '+str(ll['fadeupGain']))
|
||||
#print('fadedownPoint: '+str(ll['fadedownPoint']))
|
||||
print('fadedownGain: '+str(ll['fadedownGain']))
|
||||
print('duckUpGain: '+str(ll['duckUpGain']))
|
||||
print('duckDownGain: '+str(ll['duckDownGain']))
|
||||
print('talkStartPoint: '+str(ll['talkStartPoint']))
|
||||
print('talkEndPoint: '+str(ll['talkEndPoint']))
|
||||
print('hookMode: '+str(ll['hookMode']))
|
||||
print('hookStartPoint: '+str(ll['hookStartPoint']))
|
||||
print('hookEndPoint: '+str(ll['hookEndPoint']))
|
||||
print('eventLength: '+str(ll['eventLength']))
|
||||
print('linkEventName: '+str(ll['linkEventName']))
|
||||
print('linkStartTime: '+str(ll['linkStartTime']))
|
||||
print('linkStartSlop: '+str(ll['linkStartSlop']))
|
||||
print('linkEndSlop: '+str(ll['linkEndSlop']))
|
||||
print('linkId: '+str(ll['linkId']))
|
||||
print('linkEmbedded: '+str(ll['linkEmbedded']))
|
||||
print('extStartTime: '+str(ll['extStartTime']))
|
||||
print('extLength: '+str(ll['extLength']))
|
||||
print('extCartName: '+str(ll['extCartName']))
|
||||
print('extData: '+str(ll['extData']))
|
||||
print('extEventId: '+str(ll['extEventId']))
|
||||
print('extAnncType: '+str(ll['extAnncType']))
|
||||
print('')
|
||||
|
||||
|
||||
# print(': '+ll[''])
|
Loading…
x
Reference in New Issue
Block a user