forked from btccom/Blockchain-Known-Pools
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gen-old-pools: arg parser, allow specifying dir
- Loading branch information
Showing
1 changed file
with
41 additions
and
32 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import json | ||
import glob | ||
import sys | ||
|
||
output_file_name = "pools.json" | ||
|
||
if len(sys.argv) == 2: | ||
print(f"Using {sys.argv[1]} as output file name.") | ||
output_file_name = sys.argv[1] | ||
|
||
entity_files = glob.glob("pools/*.json") | ||
|
||
addresses = dict() | ||
tags = dict() | ||
|
||
for file_path in entity_files: | ||
with open(file_path, "r") as f: | ||
e = json.load(f) | ||
name = e["name"] | ||
link = e["link"] | ||
for addr in e["addresses"]: | ||
addresses[addr] = { "name": name, "link": link } | ||
for tag in e["tags"]: | ||
tags[tag] = { "name": name, "link": link } | ||
|
||
# sort dicts to be at least somewhat deterministic | ||
addresses = dict(sorted(addresses.items())) | ||
tags = dict(sorted(tags.items())) | ||
|
||
with open(output_file_name, "w") as out: | ||
content = { | ||
"payout_addresses": addresses, | ||
"coinbase_tags": tags | ||
} | ||
json.dump(content, out, indent = 2, ensure_ascii=False) | ||
|
||
DEFAULT_ENTITIES_DIR = "pools/" | ||
DEFAULT_OUTPUT = "pools.json" | ||
|
||
def main(args): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("output", default=DEFAULT_OUTPUT, type=str, help="output file name", nargs="?") | ||
parser.add_argument("entities", default=DEFAULT_ENTITIES_DIR, type=str, help="entities directory", nargs="?") | ||
args = parser.parse_args(args) | ||
|
||
if args.output != DEFAULT_OUTPUT: | ||
print(f"Using {args.output} as output file name.") | ||
|
||
entity_files = glob.glob(args.entities + "/*.json") | ||
|
||
addresses = dict() | ||
tags = dict() | ||
|
||
for file_path in entity_files: | ||
with open(file_path, "r") as f: | ||
e = json.load(f) | ||
name = e["name"] | ||
link = e["link"] | ||
for addr in e["addresses"]: | ||
addresses[addr] = { "name": name, "link": link } | ||
for tag in e["tags"]: | ||
tags[tag] = { "name": name, "link": link } | ||
|
||
# sort dicts to be at least somewhat deterministic | ||
addresses = dict(sorted(addresses.items())) | ||
tags = dict(sorted(tags.items())) | ||
|
||
with open(args.output, "w") as out: | ||
content = { | ||
"payout_addresses": addresses, | ||
"coinbase_tags": tags | ||
} | ||
json.dump(content, out, indent = 2, ensure_ascii=False) | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |