def date_range(start: str, end: str, timeframe: str) -> []: start = timedate_utils.datestr_to_ts(start) end = timedate_utils.datestr_to_ts(end) timeframe = timedate_utils.timedelta_to_sec(timeframe) res = [start] while True: start = start + datetime.timedelta(seconds=timeframe) # print( start ) if start >= end: break res.append(start) return res
def get_import_requests(config, time_delta) -> []: imports = [] for request in config['master_api'].get_imports(): create_time = timedate_utils.datestr_to_ts(request['create_time']) create_time = timedate_utils.to_sec_since_epoch(create_time) if time_delta: if time_delta <= create_time: imports.append(request) else: imports.append(request) return imports
def get_users( config:{}, instance_name:str=None, summary=False, time_delta:int=None ): users = [] brief = [] for instance_id in config['instances']: if instance_name and instance_id != instance_name: continue if config['instances'][ instance_id]['name'] != instance_id: continue instance = config['instances'][ instance_id] instance_users = [] tmp_users = instance['api'].get_users() brief.append({'name': instance['name'], 'users': len(tmp_users)}) for tmp_user in tmp_users: if 'update_time' in tmp_user and time_delta: update_time = timedate_utils.datestr_to_ts(tmp_user['update_time']) update_time = timedate_utils.to_sec_since_epoch( update_time) if time_delta > update_time: continue del tmp_user['update_time'] tmp_user['instance'] = instance['name'] tmp_user['active'] = bool(tmp_user['active']) tmp_user['deleted'] = bool(tmp_user['deleted']) instance_users.append( tmp_user ) users += sorted(instance_users, key=lambda x: x['email'].lower()) if summary: return brief return users
def __init__(self, start: str, end: str, interval: str): self._start = timedate_utils.datestr_to_ts(start) self._end = timedate_utils.datestr_to_ts(end) self._timeframe = timedate_utils.timedelta_to_sec(interval)