Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 33 lines 926 B view raw
1#! /usr/bin/env nix-shell 2#! nix-shell -i python3 -p "python3.withPackages(ps: with ps; [ pyyaml toml ])" 3 4import csv 5from pathlib import Path 6import sys 7import toml 8import yaml 9 10requests_csv_path = Path(sys.argv[1]) 11registry_path = Path(sys.argv[2]) 12 13# Generate list of tuples (UUID, count) 14rows = [] 15with open(requests_csv_path) as f: 16 reader = csv.reader(f) 17 for row in reader: 18 if row[2] == "user": 19 # Get UUID and request_count 20 rows.append((row[0], int(row[4]))) 21rows.sort(key=(lambda x: x[1]), reverse=True) 22 23# Build a map from UUID -> name 24registry = toml.load(registry_path / "Registry.toml") 25uuid_to_name = {k: v["name"] for k, v in registry["packages"].items()} 26 27results = [] 28for (uuid, count) in rows: 29 name = uuid_to_name.get(uuid) 30 if not name: continue 31 results.append({ "uuid": uuid, "name": uuid_to_name.get(uuid), "count": count }) 32 33yaml.dump(results, sys.stdout, default_flow_style=False)