def create_csv(service, report_date, start_date, end_date, dois):
# Open temp csv file to write data
filedata = io.BytesIO()
writer = csv.writer(filedata)
#Run Google Analytics query
data = run_query(service, start_date, end_date, 'ga:totalEvents', 'ga:eventLabel', 'ga:eventAction==download')
rows = data.get('rows')
#1. Write client-report data to csv
writer.writerow(["My Fancy Analytics Report!"])
writer.writerow(["Generated on " + report_date])
writer.writerow(["Data for " + start_date + " to " + end_date])
writer.writerow([])
writer.writerow(["Aggregate Data"])
writer.writerow(["Items in repository", len(dois)])
writer.writerow(["Items downloaded at least once", len(rows)])
writer.writerow(["Items linked to at least 1 ORCID iD"])
writer.writerow([])
writer.writerow(["Item Data"])
writer.writerow(["DOI", "Downloads", "ORCID Records with this DOI"])
if rows is not None:
for r in rows:
writer.writerow([r[0], r[1]])
writer.writerow([])
return filedata.getvalue()
#MAIN FUNCTION
评论列表
文章目录