"""Companies registered in the last 3 days in NY, CO, CT and OR.

Runs the Apify Actor https://apify.com/andreaajohansen/us-new-business-filings 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 = {
    "states": ["NY", "CO", "CT", "OR"],
    "lastNDays": 3,
    "maxItems": 50,
}

run = client.actor("andreaajohansen/us-new-business-filings").call(run_input=run_input)
items = client.dataset(run["defaultDatasetId"]).list_items().items
print(f"{len(items)} rows")
for item in items:
    print(item["filingDate"], item["filingState"], item["entityType"], item["entityName"])
