-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple_queries.py
59 lines (49 loc) · 1.62 KB
/
multiple_queries.py
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
from pprint import pprint
import requests
import os
OS_API_KEY = os.getenv("OS_API_KEY")
if not OS_API_KEY:
raise ValueError("The OS_API_KEY environment variable is not set")
def main():
# Prepare authentication using the Authorization header
headers = {
"Authorization": OS_API_KEY,
}
# Prepare two queries for one request
query = {
"queries": {
"query-A": {
"schema": "Person",
"properties": {
"name": ["Arkadiii Romanovich Rotenberg", "Ротенберг Аркадий"],
"birthDate": ["1951"],
},
},
"query-B": {
"schema": "Company",
"properties": {"name": ["Stroygazmontazh"], "jurisdiction": ["Russia"]},
},
}
}
# Make the request
response = requests.post(
"https://api.opensanctions.org/match/default", headers=headers, json=query
)
# Check for HTTP errors
response.raise_for_status()
for query_id in query["queries"].keys():
print(f"\nResults for query {query_id}:")
# Get the ID, name, match, score, and features for each result
results = []
for result in response.json()["responses"][query_id]["results"]:
results.append(
{
"id": result["id"],
"name": result["properties"]["name"],
"match": result["match"],
}
)
# print it out with nice formatting
pprint(results, sort_dicts=False)
if __name__ == "__main__":
main()