import yaml
import csv
import glob
yaml_files = glob.glob('./ipl/*.yaml')
rows=[]
for i,each_file in enumerate(yaml_files):
print("Processing file {} of {} file name: {}".format(i+1,len(yaml_files),each_file))
with open(each_file) as f:
data = yaml.safe_load(f)
values=dict()
values["date"]=data["info"]['dates']
values["winner"]=data["info"]["outcome"].get("winner", "Eliminator match - no winner")
values["mvp"]=data["info"].get("player_of_match", ['N/A'])[0]
rows.append([values["date"],values["winner"],values["mvp"]])
with open('output_csv_file.csv', 'w', newline='') as out:
csv_writer = csv.writer(out)
csv_writer.writerow(["date","winner","mvp"])
csv_writer.writerows(rows)
print("Output file output_csv_file.csv created")
Editor is loading...