def retrieve_topics(revids):
  """Gets the topics for a collection of revision ids."""
  headers = {"Accept": "application/json"}
  params = {
      "models": "drafttopic",
      "revids": "|".join(str(x) for x in revids.values())
  }
  response = request_helper(ORES_ENDPOINT, headers=headers, params=params)
  response_json = response.json()

  output = {}
  scores = response_json["enwiki"]["scores"]
  reverse_lookup = {revid: pageid for pageid, revid in revids.items()}
  for revid, predictions in scores.items():
    # Get top prediction
    probabilities = predictions["drafttopic"]["score"]["probability"]
    topic, _ = sorted(list(probabilities.items()), key=lambda x: x[1]).pop()

    output[reverse_lookup[int(revid)]] = topic
  return output
Gets the topics for a collection of revision ids.
language/fruit/scripts/get_topics.py