google_analytics.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:orcid-demo 作者: lizkrznarich 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号