"""Top 20 password-manager extensions on addons.mozilla.org.

Runs the Apify Actor https://apify.com/andreaajohansen/firefox-addons-amo and prints the results.

Setup:
    pip install apify-client
    export APIFY_TOKEN=...   # your own token from https://console.apify.com/settings/integrations

Pay per result: you are charged by Apify for the rows you get (see the Actor's Pricing tab).
"""
import os
import sys

from apify_client import ApifyClient

token = os.environ.get("APIFY_TOKEN")
if not token:
    sys.exit("Set the APIFY_TOKEN environment variable first.")

client = ApifyClient(token)
run_input = {
    "searchQueries": ["password manager"],
    "maxItems": 20,
}

run = client.actor("andreaajohansen/firefox-addons-amo").call(run_input=run_input)
items = client.dataset(run["defaultDatasetId"]).list_items().items
print(f"{len(items)} rows")
for item in items:
    print(item["averageDailyUsers"], item["ratingAverage"], item["name"])
