competitive corporate compliance
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
795 B

import random
import json
import yaml
def main():
with open('test.yml', 'r') as f:
doc = yaml.safe_load(f)
contents = doc['contents']
parse_contents_items(contents)
with open('result.json', 'w') as f:
json.dump(contents, f, indent=4)
def parse_contents_items(contents, layer=0):
assert(type(contents)==type([]))
for item in contents:
if 'contents' in item:
parse_contents_items(item['contents'], layer+1)
if 'count' in item['contents'][0].keys():
item['time'] = random.randint(100,150)/100
item['count'] = sum([s['count'] for s in item['contents']])
else:
item['time'] = random.randint(5,20)/100
item['count'] = 10
if __name__=="__main__":
main()