Last active
August 19, 2018 15:49
-
-
Save tjkendev/c4fc58ec010d068a7ae9fcaaac0e6020 to your computer and use it in GitHub Desktop.
Google Playの課金データを取得
This file contains 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"#jsで取得したCSVデータを'data.csv'で保存した上で読み込む\n", | |
"import pandas as pd\n", | |
"df = pd.read_csv('./data.csv')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"types = {}\n", | |
"print(len(df))\n", | |
"for i in range(len(df)):\n", | |
" l = df.iloc[i]\n", | |
" \n", | |
" price = l[3].replace('¥', '').replace(',', '')\n", | |
" if \"$\" in price:\n", | |
" continue\n", | |
" types.setdefault(l[4], []).append((l[1], l[2], int(price)))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for k, v in types.items():\n", | |
" print(k, len(v))\n", | |
"print(len(types['Android アプリ']))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"purchases = types['Android アプリ']\n", | |
"print(*purchases, sep='\\n')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import re" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"r_name = re.compile('^([^(]+) \\((.+)\\)$')\n", | |
"r_day = re.compile('^(\\d+)年(\\d+)月(\\d+)日$')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"items = {}\n", | |
"moneys = {}\n", | |
"for name, day, price in purchases:\n", | |
" m_name = r_name.match(name)\n", | |
" assert m_name is not None\n", | |
" item_name, app_name = m_name.groups()\n", | |
" \n", | |
" m_day = r_day.match(day)\n", | |
" assert m_day is not None\n", | |
" year, month, day = m_day.groups()\n", | |
"\n", | |
" moneys[app_name] = moneys.get(app_name, 0) + price\n", | |
" items.setdefault(app_name, []).append((item_name, price, year, month, day))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for app_name, money in moneys.items():\n", | |
" print(\"%s: %d\" % (app_name, money))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
This file contains 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
// 以下ページで購入データを全表示した上で以下スクリプトを実行すると | |
// 購入データのCSVが出力される | |
// https://play.google.com/store/account?feature=gp_receipt | |
(function get_csv_purchase_data() { | |
const s = ["0,1,2,3,4,5"] // 列の名前 | |
$(".my-account-purchase-row").each(function(i, e){ | |
const el = $(e).find('.my-account-purchase-col') | |
const tmp = [] | |
el.each(function(i, e){ | |
tmp.push('"' + $(e).text().trim() + '"') | |
}) | |
s.push(tmp.join(",")); | |
}) | |
return s.join('\n') | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment