I have script below that will write every night to a CSV
. I would like to change that process and write directly to the Xlsx
Workbook
named NHL, Sheet
Skater_Home in col
AB row
1. I've read a couple other post's using the previously created csv to import into an existing xlsx
. I can't seem to find whether or not I can just write to it directly without the CSV
process.
import csv
import requests
import os
outfile = open("NHL_Skater_HOME_TOI.csv","a",newline='')
writer = csv.writer(outfile)
writer.writerow(["Player", "GameId", "EvTOI", "PpTOI", "ShTOI"])
req = requests.get('http://www.nhl.com/stats/rest/skaters?isAggregate=false&reportType=basic&isGame=true&reportName=timeonice&sort=[{%22property%22:%22playerName%22,%22direction%22:%22ASC%22}]&factCayenneExp=gamesPlayed%3E=1&cayenneExp=gameDate%3E=%222017-10-04%22%20and%20gameDate%3C=%222017-12-31%22%20and%20gameTypeId=2%20and%20gameLocationCode=%22H%22')
data = req.json()['data']
for item in data:
Player = item['playerName']
GameId = item['gameId']
EvTOI = item['evTimeOnIce']
PpTOI = item['ppTimeOnIce']
ShTOI = item['shTimeOnIce']
print(Player, GameId, EvTOI, PpTOI, ShTOI)
writer.writerow([Player, GameId, EvTOI, PpTOI, ShTOI])
outfile.close()