def main()

in monitoring/stv_tool.py [0:0]


def main(argv):
  parser = argparse.ArgumentParser(description="Calculate a winner for a vote")
  parser.add_argument('raw_file')
  parser.add_argument("-s", "--seats", dest="seats", type=int,
                      help="Number of seats available, default 9",
                      default=9)
  parser.add_argument("-v", "--verbose", dest="verbose", action="store_true",
                      help="Enable verbose logging", default=False)
  args = parser.parse_args(argv)

  global VERBOSE
  VERBOSE = args.verbose

  if not os.path.exists(args.raw_file):
    parser.print_help()
    sys.exit(1)

  # Get mapping from vote label (typically "a" to "z") to human name.
  labelmap = read_nominees(args.raw_file)

  # Construct a label-sorted list of names from the labelmap.
  names = [name for _, name in sorted(labelmap.items())]

  # Turn votes using labels into by-name.
  if args.raw_file.endswith('.json'):
    ### noted on 2025-03-06:
    ### this appears totally broken. The prior-year raw JSON files have
    ### labels such as "AK" and "AB", yet the labels extracted from
    ### board_nominations.ini uses labels like "k" and "b".
    ### QUESTION: do new .json files have a mapping in them? eg. who is "AK"?
    votes_by_label = read_jsonvotes(args.raw_file)
    votes = [[labelmap[l.lower()] for l in vote.split()] for vote in votes_by_label]
  else:
    votes_by_label = read_votefile(args.raw_file)
    votes = [[labelmap[l] for l in vote] for vote in votes_by_label]

  candidates = run_stv(names, votes, args.seats)
  candidates.print_results()
  print('Done!')