def main(listings): from time import sleep id_to_address = map_existing_entries(sorted(glob("tokens/0x*.yaml"))) for listing in listings: sleep(12) result = process_listing(listing) if result is None: continue (updated_listing, current_addresses) = result existing_addresses = id_to_address[listing["id"]] for address in existing_addresses - current_addresses: logging.warning("'%s' has deprecated %s", listing["website_slug"], address) old_listing = read_entry("tokens/{}.yaml".format(address)) old_listing.update({"_DEPRECATED": True}) del old_listing["address"] write_token_entry(address, old_listing) for address in current_addresses: write_token_entry(address, updated_listing)
def map_existing_entries(files, exclude_deprecated=True): """ Returns a hash keyed by CoinMarketCap asset ID with sets of Ethereum addresses known to be associated with that asset ID. """ entries = ((entry["id"], entry["address"]) for entry in (read_entry(fn) for fn in files) if not (exclude_deprecated and entry.get("_DEPRECATED", False))) return { e[0]: set(g[1] for g in e[1]) for e in groupby(sorted(entries), key=lambda e: e[0]) }
from glob import glob import json import yaml from helpers import read_entry INDEX_KEYS = ["id", "address", "name", "symbol"] def abridged_entry(entry): return {k: entry[k] for k in INDEX_KEYS} if __name__ == "__main__": files = sorted(glob("tokens/0x*.yaml")) entries = list(read_entry(fn) for fn in files) for entry in entries: json_fn = "tokens/{}.json".format(entry["address"]) with open(json_fn, "w") as outfile: json.dump(entry, outfile, separators=(',', ':')) with open("tokens/bundle.json", "w") as outfile: json.dump(entries, outfile, separators=(',', ':')) with open("tokens/index.json", "w") as outfile: json.dump( list( abridged_entry(entry) for entry in entries if not entry.get("_DEPRECATED", False)), outfile, separators=(',', ':'))