mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 19:08:12 +00:00
tools: add a simple tool to compare live t.io/coins with current json
This commit is contained in:
parent
c1cea21bb5
commit
0a2f9bb10c
60
tools/diffize_coins_details.py
Executable file
60
tools/diffize_coins_details.py
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import click
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import tempfile
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
LIVE_URL = "https://trezor.io/static/json/coins_details.json"
|
||||||
|
COINS_DETAILS = os.path.join(
|
||||||
|
os.path.dirname(__file__), "..", "defs", "coins_details.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def diffize_file(coins_details, tmp):
|
||||||
|
coins_list = list(coins_details["coins"].values())
|
||||||
|
for coin in coins_list:
|
||||||
|
coin.pop("marketcap_usd", None)
|
||||||
|
links = coin.get("links", {})
|
||||||
|
wallets = coin.get("wallet", {})
|
||||||
|
for link in links:
|
||||||
|
links[link] = links[link].rstrip("/")
|
||||||
|
for wallet in wallets:
|
||||||
|
wallets[wallet] = wallets[wallet].rstrip("/")
|
||||||
|
|
||||||
|
if not coin.get("wallet"):
|
||||||
|
coin.pop("wallet", None)
|
||||||
|
|
||||||
|
coins_list.sort(key=lambda c: c["name"])
|
||||||
|
|
||||||
|
for coin in coins_list:
|
||||||
|
name = coin["name"]
|
||||||
|
for key in coin:
|
||||||
|
print(name, "\t", key, ":", coin[key], file=tmp)
|
||||||
|
tmp.flush()
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
def cli():
|
||||||
|
"""Compare data from trezor.io/coins with current coins_details.json
|
||||||
|
|
||||||
|
Shows a nicely formatted diff between the live version and the trezor-common
|
||||||
|
version. Useful for catching auto-generation problems, etc.
|
||||||
|
"""
|
||||||
|
live_json = requests.get(LIVE_URL).json()
|
||||||
|
with open(COINS_DETAILS) as f:
|
||||||
|
coins_details = json.load(f)
|
||||||
|
|
||||||
|
Tmp = tempfile.NamedTemporaryFile
|
||||||
|
with Tmp("w") as tmpA, Tmp("w") as tmpB:
|
||||||
|
diffize_file(live_json, tmpA)
|
||||||
|
diffize_file(coins_details, tmpB)
|
||||||
|
subprocess.call(["diff", "-u", "--color=auto", tmpA.name, tmpB.name])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
cli()
|
Loading…
Reference in New Issue
Block a user