-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite_technology_lookup.py
More file actions
36 lines (24 loc) · 1.06 KB
/
Copy pathwebsite_technology_lookup.py
File metadata and controls
36 lines (24 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Look up website technologies and print Dataset items as JSON lines."""
from __future__ import annotations
import json
import os
from pathlib import Path
from typing import Any, Iterator
from apify_client import ApifyClient
ACTOR_ID = "datascraperes/website-technology-lookup"
ROOT = Path(__file__).resolve().parents[2]
INPUT_PATH = ROOT / "data" / "sample-input.json"
def run_website_technology_lookup(run_input: dict[str, Any]) -> Iterator[dict[str, Any]]:
"""Run the hosted Actor and yield its default Dataset items."""
token = os.environ.get("APIFY_API_TOKEN")
if not token:
raise RuntimeError("Set APIFY_API_TOKEN before running this example.")
client = ApifyClient(token)
run = client.actor(ACTOR_ID).call(run_input=run_input)
yield from client.dataset(run["defaultDatasetId"]).iterate_items()
def main() -> None:
run_input = json.loads(INPUT_PATH.read_text(encoding="utf-8"))
for item in run_website_technology_lookup(run_input):
print(json.dumps(item, ensure_ascii=False))
if __name__ == "__main__":
main()