def get_session_by_id(session_id): """ Same as /sessions/{sessionId} args: session_id: int returns: dict """ name = 'sessions' data = get_mock_data(name) results = [d for d in data['results'] if d['id']==str(session_id)] return results_display(results)
def get_site_by_name(site_name): """ Same as /sites/{siteName} args: site_name: str returns: dict """ name = 'sites' data = get_mock_data(name) results = [d for d in data['results'] if d['om_user_settings_standalone_site']==site_name] return results_display(results)
def get_captions_by_session(session_id, start=None, limit=None): """ Same as /sesssion/{sessionId}/captions args: session_id: int kwargs: start: int limit: int """ group = get_mock_data("captions_by_session/groupings")[str(session_id)] results = get_mock_data( os.path.join('captions_by_session', group))[str(session_id)] if not start: start = 0 if not limit: limit = len(results) return results_display(results[start:start+limit])
def get_cuepoints_by_session(session_id, start=None, limit=None): """ Same as /sesssion/{sessionId}/captions args: session_id: int kwargs: start: int limit: int """ name = 'cuepoints' data = get_mock_data(name) results = [d for d in data['results'] if d['session_id']==str(session_id)] if not start: start = 0 if not limit: limit = len(results) return results_display(results[start:start+limit])
def filter_results(json_data, model, **kwargs): """ Filters stored data based on kwargs to mock api queries args: json_data: stored api json data model: json object model kwargs: category: array of ints, default to None createdAfter: int, default to None updatedAfter: int, default to None state: str, default to None livestream: bool, default to None billId: string, default to None """ check_filters(model, kwargs) category = kwargs.get('category', None) createdAfter = kwargs.get('createdAfter', None) updatedAfter = kwargs.get('updatedAfter', None) state = kwargs.get('state', None) livestream = kwargs.get('livestream', None) billId = kwargs.get('billId', None) start = kwargs.get('start', 0) if not start: start = 0 limit = kwargs.get('limit', None) total_results = [] for result_obj in json_data['results']: obj_passes = True try: if category: if not any([d['id'] in category for d in result_obj['categories']]): obj_passes = False if obj_passes and createdAfter: if not int(result_obj['created']) < int(createdAfter): obj_passes = False if obj_passes and updatedAfter: if not int(result_obj['updated']) > int(updatedAfter): obj_passes = False if obj_passes and state: if not (result_obj['state']==state or result_obj['state_abbrev']==state): obj_passes = False if obj_passes and livestream!=None: if not result_obj['livestream'] == str(int(livestream)): obj_passes = False if obj_passes and billId: if not any(('HB19-1011' in v) for v in result_obj.values() if v!=None): obj_passes = False except KeyError: obj_passes = False if obj_passes: total_results.append(result_obj) if limit: results = total_results[start:start+limit] else: results = total_results[start:] mock_query_res = {'start': start, 'size': len(results), 'results': results} return results_display(results, start, limit, len(total_results))