-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeople.py
75 lines (62 loc) · 2.35 KB
/
people.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import requests
import pandas as pd
import pprint
from auth import key
from crunch_library import pullData
url = 'https://api.crunchbase.com/api/v4/searches/people/'
def peopleQuery(limit: int = 1000, uuidLast: str = '', uuidList: list = None, gender: str = None):
query = {
"field_ids": [
"entity_def_id",
"facet_ids",
"gender",
"identifier",
"name",
"uuid"
],
"query": [], # because a person does not need to be from the US to have a US company founded
'limit': limit
}
if uuidList is not None: # only if it is not None, we are going to specify the uuid
query['query'].append({
"type": "predicate",
"field_id": "uuid",
# "operator_id": "eq",
"operator_id": "includes",
"values": uuidList
})
if gender is not None: # only if it is not None, we are going to specify the gender
query['query'].append({
"type": "predicate",
"field_id": "gender",
"operator_id": "eq",
"values": [
gender
]
})
return query
def flattenPeopleEntity(entity: dict):
if 'facet_ids' in entity['properties']:
facetIds = entity['properties']['facet_ids']
facetIdsString = ', '.join(facetIds)
else:
facetIdsString = 'null'
if 'gender' not in entity['properties']: # processes all the blanks
gender = 'null' # currently, hard codes null
else:
gender = entity['properties']['gender']
entityList = [entity['uuid'],
entity['properties']['name'],
facetIds,
gender]
# print(f'Entity list before return: {entityList=}')
return entityList
columnHeaders = ['uuid',
'name',
'facetIds',
'gender']
if __name__ == '__main__':
# test values if you wanted to run only this program
filename = 'datasets/people.csv'
uuidList = []
print(pullData(filename, url, peopleQuery(uuidList = uuidList), flattenFunction = flattenPeopleEntity, columnHeaders = columnHeaders))