I am very new to python and I have csv problem. I have a code to extract data from Futbin website but I don't find how to do to export these datas to a csv file. The datas shown in Python are exactly what I need so the last step for me is to exctract them.
Here is the code :
import requests
import csv
from datetime import datetime
player_ids = {
'Maguire OTW': 50534911,
'Pulisic OTW' : 50559444,
}
for (name,id) in player_ids.items():
r = requests.get('https://www.futbin.com/20/playerGraph?type=yesterday&year=20&player={0}'.format(id))
data = r.json()
print()
print(name)
#Change ps to xbox or pc to get other prices
for price in data['ps']:
#There is extra zeroes in response.
date = datetime.utcfromtimestamp(price[0] / 1000).strftime('%Y-%m-%d')
price = price[1]
print(date,price)
Thanks a lot for your help
Copy Comment: When I add this at the end of the code :
with open('yesterdayok.csv', 'w') as csv_file: csv_writer = csv.writer(csv_file) csv_writer.writerow(date)
it creates the csv file but inside there's only 1 date, I need all the datas generated by the code.