From b9164bad15add428d875f01fed956fa0173a294a Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Sun, 12 Dec 2021 16:28:45 -0500 Subject: [PATCH] 2021-12-12 Fred Gleason * Added a 'SchedulerCode()' type class to the 'rivwebpyapi' API. * Modified the 'rivwebpyapi.ListCartSchedCodes()' call to return a list of 'rivwebpyapi.SchedulerCode' objects. * Modified the 'rivwebpyapi.ListSchedulerCodes()' call to return a list of 'rivwebpyapi.SchedulerCode' objects. Signed-off-by: Fred Gleason --- ChangeLog | 6 +++ apis/rivwebpyapi/api/rivwebpyapi.py | 48 ++++++++++--------- .../tests/list_cart_sched_codes.py | 4 +- .../rivwebpyapi/tests/list_scheduler_codes.py | 4 +- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6354b0bf..aea96f99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22763,3 +22763,9 @@ * Added an 'SaveLog()' method to the 'rivwebpyapi' API. 2021-12-12 Fred Gleason * Added a 'RivendellType()' base class to the 'rivwebpyapi' API. +2021-12-12 Fred Gleason + * Added a 'SchedulerCode()' type class to the 'rivwebpyapi' API. + * Modified the 'rivwebpyapi.ListCartSchedCodes()' call to return + a list of 'rivwebpyapi.SchedulerCode' objects. + * Modified the 'rivwebpyapi.ListSchedulerCodes()' call to return + a list of 'rivwebpyapi.SchedulerCode' objects. diff --git a/apis/rivwebpyapi/api/rivwebpyapi.py b/apis/rivwebpyapi/api/rivwebpyapi.py index 1216a7aa..9dd0c267 100755 --- a/apis/rivwebpyapi/api/rivwebpyapi.py +++ b/apis/rivwebpyapi/api/rivwebpyapi.py @@ -219,6 +219,11 @@ LOGLINE_FIELDS={ 'extAnncType': 'string' } +SCHEDULER_CODE_FIELDS={ + 'code': 'string', + 'description': 'string' +} + class RivWebPyApi_ListHandler(ContentHandler): def __init__(self,base_tag,fields): self.__output=[] @@ -414,6 +419,10 @@ class LogLine(RivendellType): def __init__(self,values={}): super().__init__(LOGLINE_FIELDS,values) +class SchedulerCode(RivendellType): + def __init__(self,values={}): + super().__init__(SCHEDULER_CODE_FIELDS,values) + class rivwebpyapi(object): """ Create a 'RivWebPyApi' object for accessing the Web API. @@ -1279,7 +1288,7 @@ class rivwebpyapi(object): def ListCartSchedCodes(self,cart_number): """ Returns the set of scheduler codes associated with a Rivendell - cart (list of dictionaries) + cart (list of rivwebpyapi.SchedulerCode objects). Takes the following arguments: @@ -1308,17 +1317,15 @@ class rivwebpyapi(object): if(r.status_code!=requests.codes.ok): self.__throwError(response=r) - # - # Generate the output dictionary - # - fields={ - 'code': 'string', - 'description': 'string' - } - handler=RivWebPyApi_ListHandler(base_tag='schedCode',fields=fields) + handler=RivWebPyApi_ListHandler(base_tag='schedCode', + fields=SCHEDULER_CODE_FIELDS) xml.sax.parseString(r.text,handler) + out=handler.output() + ret=[] + for item in out: + ret.append(SchedulerCode(item)) - return handler.output() + return ret def ListCut(self,cart_number,cut_number): """ @@ -1603,7 +1610,7 @@ class rivwebpyapi(object): def ListSchedulerCodes(self): """ Returns a list of all defined Rivendell schedule codes - (list of dictionaries) + (list of rivwebpyapi.SchedulerCode objects). """ # @@ -1625,14 +1632,15 @@ class rivwebpyapi(object): # # Generate the output dictionary # - fields={ - 'code': 'string', - 'description': 'string' - } - handler=RivWebPyApi_ListHandler(base_tag='schedCode',fields=fields) + handler=RivWebPyApi_ListHandler(base_tag='schedCode', + fields=SCHEDULER_CODE_FIELDS) xml.sax.parseString(r.text,handler) + out=handler.output() + ret=[] + for item in out: + ret.append(SchedulerCode(item)) - return handler.output() + return ret def ListServices(self,trackable): """ @@ -2161,12 +2169,6 @@ class rivwebpyapi(object): if(r.status_code!=requests.codes.ok): self.__throwError(response=r) - - - - - - def SavePodcast(self,cast_id,filename): """ Save posted podcast audio to the Rivendell audio store. diff --git a/apis/rivwebpyapi/tests/list_cart_sched_codes.py b/apis/rivwebpyapi/tests/list_cart_sched_codes.py index 6c7ddccb..ce7164f9 100755 --- a/apis/rivwebpyapi/tests/list_cart_sched_codes.py +++ b/apis/rivwebpyapi/tests/list_cart_sched_codes.py @@ -77,6 +77,6 @@ except rivwebpyapi.RivWebPyError as err: # Display the code list # for code in codes: - print('code: '+str(code['code'])) - print('description: '+str(code['description'])) + for key in code.values(): + print(key+': '+str(code.values()[key])) print('') diff --git a/apis/rivwebpyapi/tests/list_scheduler_codes.py b/apis/rivwebpyapi/tests/list_scheduler_codes.py index f1dee911..b2e08c53 100755 --- a/apis/rivwebpyapi/tests/list_scheduler_codes.py +++ b/apis/rivwebpyapi/tests/list_scheduler_codes.py @@ -72,6 +72,6 @@ except rivwebpyapi.RivWebPyError as err: # Display the code list # for code in codes: - print('code: '+str(code['code'])) - print('description: '+str(code['description'])) + for key in code.values(): + print(key+': '+str(code.values()[key])) print('')