Created
November 29, 2012 10:46
-
-
Save gin0606/4168151 to your computer and use it in GitHub Desktop.
itunesConnectから日毎のダウンロード数のファイル落としてくる奴。使い方は http://zaru.tofu-kun.org/2011/11/08/itunesconnectからアプリダウンロード数レポートを自動取/ を見ると分かる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
# -*- coding: utf-8; -*- | |
import os | |
import sys | |
args = sys.argv | |
import gzip | |
import urllib | |
import urllib2 | |
from datetime import datetime | |
URL = 'https://reportingitc.apple.com/autoingestion.tft' | |
post_data = { | |
'USERNAME' : args[1], | |
'PASSWORD' : args[2], | |
'VNDNUMBER' : args[3], | |
'TYPEOFREPORT' : args[4], | |
'DATETYPE' : args[5], | |
'REPORTTYPE' : args[6], | |
'REPORTDATE' : args[7], | |
} | |
if __name__ == '__main__': | |
req = urllib2.Request(URL + '?') | |
req.add_header('Content-Type', 'application/x-www-form-urlencoded') | |
# postのパラメーター追加 | |
params = urllib.urlencode(post_data) | |
req.add_data(params) | |
# POSTリクエスト | |
res = urllib2.urlopen(req) | |
data = res.read() | |
# 日付で保存 | |
gz_filename = post_data['REPORTDATE'] + '.txt.gz' | |
f = open(gz_filename, 'w') | |
f.write(data) | |
f.close() | |
# gzファイル解答して読み込んで消す | |
fp = gzip.open(gz_filename) | |
raw_data = fp.read() | |
fp.close() | |
os.remove(gz_filename) | |
# 扱いやすそうな感じにsplitする | |
data = [] | |
for line in raw_data.strip().split('\n'): | |
data.append(line.split('\t')) | |
# これDBにつっこんだりすればいい気がする | |
print data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment