Last active
September 22, 2019 14:54
-
-
Save kusano/9d7e1a790a17c7f698513ff8bcb9ac16 to your computer and use it in GitHub Desktop.
技術書典のかんたん後払いシステム集計スクリプト
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
// https://techbookfest.org/market/distributor/watch | |
// をChromeで開いて、開発者コンソールを開き、 | |
ws = new WebSocket("wss://s-usc1c-nss-223.firebaseio.com/.ws?v=5&ns=tbf-tokyo") | |
x = "" | |
ws.addEventListener('message', e=>{x+=e.data+"\n"}) | |
ws.send('{"t":"d","d":{"r":1,"a":"s","b":{"c":{"sdk.js.6-6-0":1}}}}') | |
// 開発者コンソールのNetwork → WS → Messagesからコピー | |
ws.send('{"t":"d","d":{"r":2,"a":"auth","b":{"cred":"????"}}}') | |
// 同じくコピー | |
ws.send('{"t":"d","d":{"r":3,"a":"q","b":{"p":"/market/handshake/distributor/????","h":""}}}') | |
x | |
// これをコピー | |
// 複数のJSONが含まれていて、長いJSONは分割されているので、良い感じに成形してtbf.jsonに保存 | |
// parse.pyを実行 |
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
import json | |
count = {} | |
price = {} | |
d = open("tbf.json", encoding="utf-8").read() | |
d = json.loads(d)["d"]["b"]["d"] | |
for k in d.keys(): | |
for i in d[k]["items"]: | |
name = d[k]["items"][i]["product"]["name"] | |
num = d[k]["items"][i]["quantity"] | |
if name not in count: | |
count[name] = 0 | |
price[name] = d[k]["items"][i]["product"]["price"] | |
count[name] += num | |
for name in count: | |
print("%s %s*%s = %s" % (name, price[name], count[name], price[name]*count[name])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment