import yaml

def yaml_loader():
  try:
    with open("content/newsPage.md", "r") as stream:
       data = yaml.load(stream, Loader=yaml.FullLoader)
       l = data['news']
       for idx, new in enumerate(l):
        #    print(idx, new['title'])
           if(idx != -1):
             with open('content/news/'+new['title'] + '.md', 'a') as outfile:
               yaml.dump(new, outfile,default_flow_style=False,encoding='utf-8',allow_unicode=True, explicit_start=True, explicit_end=True)
    #    for workload in data:
    #        print(workload)
        #  with open(workload['workload']['name'] + '.yaml', 'a') as outfile:
        #       # if you put the variable "workload" in a list, you get the '-' in the yaml, as it denotes a list item.
        #    yaml.dump([workload], outfile)
  except yaml.YAMLError as out:
    print(out)

yaml_loader()