i_jemin

Archive

← 아카이브로

파이썬으로 구글 플레이 판매(매출) 보고서 자동 다운로드 받기

매번 손으로 다운로드하는 일을 줄이려고 작성한 스크립트다. 구글 플레이 콘솔의 매출 기록들은 해당 개발자 계정과 연동된 구글 클라우드 스토리지 서비스에 저장된다.

따라서 해당 스토리지에 접근 권한을 가진 서비스 계정으로 접근하여 다운로드 받으면 된다.

DownloadReports.py

from google.cloud import storage
import os

certificationJsonFile = 'XXXXX.json'
bucketName = r'pubsite_prod_rev_XXXXXX'
reportYear = 2018


# Connecte with Service Account
storage_client = storage.Client.from_service_account_json(certificationJsonFile)

# Get Bucket contain sales data
bucket = storage_client.get_bucket(bucketName)

# Get blobs contain 'sales' prefix
prefix = 'sales'
blobs = bucket.list_blobs(prefix=prefix)


if not os.path.isdir(prefix):
    os.mkdir(prefix)

for blob in blobs:
    if str(reportYear) in blob.name:
        blob.download_to_filename(r'./' + blob.name)

https://gist.github.com/IJEMIN/195f1492d76d491f9154b399a391b956