change scraper to output new json and csv for each team

This commit is contained in:
nprasad2077 committed 2023-04-20 18:13:52 -05:00
1 parent 50af7d9fc8
commit a08f9b6117
1 file changed
+8 -5
+8 -5
View File
@@ -56,17 +56,17 @@ for team in teams:
# locate current directory
script_dir = os.path.dirname(os.path.abspath(__file__))
# CSV file
csv_output_path = os.path.join(script_dir, '..', 'data', 'output.csv')
csv_output_path = os.path.join(script_dir, '..', 'data', f'{team}_{season}_output.csv')
with open(csv_output_path, "w", newline="") as csvfile:
writer = csv.DictWriter(csvfile, fieldnames =headers)
writer = csv.DictWriter(csvfile, fieldnames=headers)
writer.writeheader()
for row in data:
writer.writerow(row)
# Save as JSON
json_output_path = os.path.join(script_dir, '..', 'data', 'output.json')
json_output_path = os.path.join(script_dir, '..', 'data', f'{team}_{season}_output.json')
with open(json_output_path, 'w') as jsonfile:
json.dump(data, jsonfile)
@@ -103,4 +103,7 @@ for team in teams:
team=row['team'],
season=row['season'],
)
player_data.save()
player_data.save()