-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathventureradar-api-example.py
More file actions
203 lines (164 loc) · 7.14 KB
/
Copy pathventureradar-api-example.py
File metadata and controls
203 lines (164 loc) · 7.14 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"""
VentureRadar Company Discovery API: A Quick Start Example
See more at: https://apify.com/johnvc/ventureradar-company-api?fpr=9n7kx3
Input schema: https://apify.com/johnvc/ventureradar-company-api/input-schema?fpr=9n7kx3
This script shows how to call the VentureRadar Company Discovery API on Apify from
Python and read its structured JSON output. It sends one or more company profile
URLs and prints the fields that matter for startup database work: sector focus,
founding year, scores, milestones, and the funding signals that say which
accelerators, incubators, grants, or awards are behind a company.
The Actor bills per company profile returned, so the default run collects exactly
one company. Pass --url one or more times to collect your own list.
Get your free Apify API key at: https://apify.com?fpr=9n7kx3
Examples:
uv run python ventureradar-api-example.py
uv run python ventureradar-api-example.py --url "https://www.ventureradar.com/organisation/Theneo/b40ae154-6867-456f-a215-d98fdae0048c"
uv run python ventureradar-api-example.py --json
"""
from __future__ import annotations
import argparse
import json
import os
from typing import Any
from apify_client import ApifyClient
from dotenv import load_dotenv
load_dotenv()
ACTOR_ID = "johnvc/ventureradar-company-api"
# A company profile URL carries BOTH the company name and the profile id.
# There is no shorthand form: a bare company name cannot be resolved.
DEFAULT_COMPANY_URLS = [
"https://www.ventureradar.com/organisation/Theneo/b40ae154-6867-456f-a215-d98fdae0048c",
]
def print_company(item: dict[str, Any]) -> None:
"""Pull the useful fields out of one company row and print them.
Fields with no value on the source profile are left out of the row entirely,
so every read below uses .get() and tolerates a thin profile.
Args:
item: One dataset row where result_type is "company".
"""
name = item.get("companyName", "(unnamed)")
founded = item.get("founded")
where = item.get("location") or item.get("country")
header = name
if where and founded:
header += f" ({where}, founded {founded})"
elif where:
header += f" ({where})"
elif founded:
header += f" (founded {founded})"
print(header)
if item.get("website"):
print(f" Website: {item['website']}")
if item.get("ownership"):
print(f" Ownership: {item['ownership']}")
focus = item.get("areasOfFocus") or item.get("keywords") or []
if focus:
print(f" Focus: {', '.join(focus)}")
# Headline score plus the sub-scores behind it.
if item.get("analystScore") is not None:
print(f" Analyst: {item['analystScore']}")
scores = item.get("scores") or {}
if scores:
parts = [f"{key}={value}" for key, value in scores.items()]
print(f" Scores: {', '.join(parts)}")
if item.get("websitePopularity"):
print(f" Popularity: {item['websitePopularity']}")
# Funding signals are the differentiated field: who backed this company,
# with a source link for each entry. They are provenance, not amounts.
signals = item.get("fundingSignals") or []
if signals:
print(f" Funding signals ({len(signals)}):")
for signal in signals:
category = signal.get("category", "signal")
source = signal.get("source", "")
print(f" - [{category}] {source}")
if signal.get("url"):
print(f" {signal['url']}")
else:
print(" Funding signals: none on record")
milestones = item.get("milestones") or []
if milestones:
print(f" Milestones ({len(milestones)}):")
for milestone in milestones:
print(f" - {milestone.get('date', '')}: {milestone.get('text', '')}")
similar = item.get("similarCompanies") or []
if similar:
print(f" Similar: {', '.join(similar)}")
if item.get("linkedin"):
print(f" LinkedIn: {item['linkedin']}")
if item.get("twitter"):
print(f" X: {item['twitter']}")
if item.get("summary"):
print(f" Summary: {item['summary']}")
print()
def print_error(item: dict[str, Any]) -> None:
"""Print one error row so a failed input never disappears silently."""
print(f"ERROR for {item.get('sourceUrl', '(unknown URL)')}")
print(f" {item.get('error_type', 'Error')}: {item.get('error_message', '')}")
print()
def run_default(client: ApifyClient, company_urls: list[str], as_json: bool) -> None:
"""Collect the given company profiles and print the results.
Args:
client: An authenticated Apify client.
company_urls: Company profile URLs to collect.
as_json: Print raw JSON rows instead of the formatted summary.
"""
# The list is kept to a single company by default to keep this first run
# inexpensive: billing is one event per company profile returned. Add more
# URLs with --url once you have your own API key and know your budget.
# The Actor accepts up to 1000 profile URLs in one run.
run_input: dict[str, Any] = {
"companyUrls": company_urls,
}
print(f"Collecting {len(company_urls)} company profile(s) ...\n")
run = client.actor(ACTOR_ID).call(run_input=run_input)
if run is None:
raise SystemExit("The Actor run did not return a result.")
# apify-client 3.x returns a typed Run object, so read the attribute.
items = list(client.dataset(run.default_dataset_id).iterate_items())
print(f"Returned {len(items)} row(s) from run {run.id}.\n")
if as_json:
print(json.dumps(items, indent=2, ensure_ascii=False, default=str))
return
companies = [row for row in items if row.get("result_type") == "company"]
errors = [row for row in items if row.get("result_type") == "error"]
for row in companies:
print_company(row)
for row in errors:
print_error(row)
# A quick deal-sourcing filter: which of these have accelerator or
# incubator provenance on record?
backed = [row for row in companies if row.get("fundingSignals")]
print(f"{len(backed)} of {len(companies)} company row(s) carry at least one funding signal.")
def main() -> None:
"""Parse arguments and run the quick start."""
parser = argparse.ArgumentParser(
description="VentureRadar Company Discovery API example",
)
parser.add_argument(
"--url",
dest="urls",
action="append",
default=None,
help=(
"A company profile URL to collect. Repeat for several companies. "
"The URL must contain both the company name and the profile id."
),
)
parser.add_argument(
"--json",
dest="as_json",
action="store_true",
help="Print the raw JSON rows instead of the formatted summary.",
)
args = parser.parse_args()
token = os.getenv("APIFY_API_TOKEN")
if not token:
raise SystemExit(
"Set APIFY_API_TOKEN in .env or the environment. "
"Get a free key at https://apify.com?fpr=9n7kx3"
)
client = ApifyClient(token)
run_default(client, args.urls or DEFAULT_COMPANY_URLS, args.as_json)
if __name__ == "__main__":
main()