def load_categories(data, path): position = [(data, -2)] for filename in os.listdir(path): section = [([filename], -1)] + [ (line.strip().split('@@@'), len(line) - len(line.lstrip())) for line in open(path + filename) ] for (caption, indent) in section: if caption[0] == '': continue while position[-1][1] > indent: position.pop() #time, expanded, marked = [''] * 3 time, expanded, marked = caption[-1].split( ',') if len(caption) > 1 else [''] * 3 item = dict(caption=caption[0], time=int(time) if time.isdigit() else None, hover=False, expanded=expanded == 'e', marked=marked == 'm', items=[]) if position[-1][1] == indent: position[-2][0]['items'].append(item) position.pop() else: position[-1][0]['items'].append(item) position.append((item, indent))
def load_categories(data, path): position = [(data, -2)] for filename in os.listdir(path): section = [([filename], -1)] + [(line.strip().split('@@@'), len(line) - len(line.lstrip())) for line in open(path + filename)] for (caption, indent) in section: if caption[0] == '': continue while position[-1][1] > indent: position.pop() #time, expanded, marked = [''] * 3 time, expanded, marked = caption[-1].split(',') if len(caption) > 1 else [''] * 3 item = dict(caption = caption[0], time = int(time) if time.isdigit() else None, hover = False, expanded = expanded == 'e', marked = marked == 'm', items = []) if position[-1][1] == indent: position[-2][0]['items'].append(item) position.pop() else: position[-1][0]['items'].append(item) position.append((item, indent))
def _parse_time(time): time = time.lower() if not time.isdigit(): time = re.split(r"\s*([\d.]+\s*[^\d\s,;]*)(?:[,;\s]|and)*", time) time = sum(map(_timespec_sec, filter(None, time))) return int(time)