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
|
|
|
|
| 1 |
+
import requests as r
|
| 2 |
+
import time
|
| 3 |
+
import urllib.parse
|
| 4 |
+
|
| 5 |
+
### This is a sample script to testing most of the annotated 990 API endpoints.
|
| 6 |
+
### The test loop only tries each parameter separately, but you can combine as many as you want
|
| 7 |
+
### to create narrower datasets. API will return EINs that match all criteria provided.
|
| 8 |
+
### See API reference sheet for more details
|
| 9 |
+
### https://docs.google.com/spreadsheets/d/1bXXKZ7kJ8UsoAVAfk8sH7yYSVB6xo8OLl1OGmSpSZ4k/edit?gid=1284351522#gid=1284351522
|
| 10 |
+
|
| 11 |
+
endpoint = 'https://givingtuesday-annotated-990.hf.space/eins/'
|
| 12 |
+
key = "<redacted>" # see your email for the api key, if you are invited to join the testing group
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
nonbinary_fields = ['taxyear', 'list_ein_zipcodes'] # TAXYEAR MUST BE 2023
|
| 16 |
+
|
| 17 |
+
less_than_fields = ['acs_fraction_poverty', 'acs_fraction_snap', 'acs_fraction_insured', 'acs_median_income', 'acs_fraction_hs', 'acs_fraction_vacant', 'acs_dep_index',
|
| 18 |
+
'mapagora_n', 'mapagora_civic_org_sum', 'mapagora_civic_opp_sum', 'mapagora_volunteer_sum', 'mapagora_membership_sum',
|
| 19 |
+
'mapagora_take_action_sum', 'mapagora_events_sum', 'mapagora_TotalPopulation', 'mapagora_BROAD', 'mapagora_REMNRTY',
|
| 20 |
+
'mapagora_POV150', 'mapagora_NOHSDP', 'mapagora_SNGPNT', 'mapagora_UNEMP', 'mapagora_civic_org_sum_normalized', 'mapagora_civic_opp_sum_normalized',
|
| 21 |
+
'mapagora_civic_opp_index', 'mapagora_volunteer_sum_normalized', 'mapagora_membership_sum_normalized', 'mapagora_take_action_sum_normalized', 'mapagora_events_sum_normalized',
|
| 22 |
+
'staff_gender_male_fraction', 'staff_gender_female_fraction',
|
| 23 |
+
]
|
| 24 |
+
greater_than_fields = [
|
| 25 |
+
'cause_area_arts_culture_humanities', 'cause_area_education', 'cause_area_universities', 'cause_area_environment',
|
| 26 |
+
'cause_area_animal_related', 'cause_area_healthcare', 'cause_area_hospitals', 'cause_area_mental_health_crisis_intervention',
|
| 27 |
+
'cause_area_voluntary_health_associations_medical_disciplines', 'cause_area_medical_research', 'cause_area_crime_legal_related',
|
| 28 |
+
'cause_area_employment', 'cause_area_food_agriculture_nutrition', 'cause_area_housing_shelter',
|
| 29 |
+
'cause_area_public_safety_disaster_preparedness_relief', 'cause_area_recreation_sports', 'cause_area_youth_development',
|
| 30 |
+
'cause_area_human_services', 'cause_area_international_foreign_affairs_national_security',
|
| 31 |
+
'cause_area_civil_rights_social_action_advocacy', 'cause_area_community_improvement_capacity_building',
|
| 32 |
+
'cause_area_philanthropy_voluntarism_grantmaking_foundations', 'cause_area_science_technology', 'cause_area_social_science',
|
| 33 |
+
'cause_area_public_societal_benefit', 'cause_area_religion_related', 'cause_area_mutual_membership_benefit', 'cause_area_unknown',
|
| 34 |
+
'opencorporates_match_confidence',
|
| 35 |
+
]
|
| 36 |
+
test_strings = {
|
| 37 |
+
'cause_area_primary_class': [
|
| 38 |
+
'Hopsitals', #'Hopsitals', # NOTE THIS IS MISSPELLED IN THE API DATA -- AND zero primary matches
|
| 39 |
+
'Food, Agriculture & Nutrition',
|
| 40 |
+
'Community Improvement & Capacity Building',
|
| 41 |
+
'Mental Health & Crisis Intervention',
|
| 42 |
+
'Food, Agriculture & Nutrition',
|
| 43 |
+
'Housing & Shelter',
|
| 44 |
+
'Human Services',
|
| 45 |
+
'Arts, Culture & Humanities',
|
| 46 |
+
'Youth Development',
|
| 47 |
+
'Community Improvement & Capacity Building',
|
| 48 |
+
'Mutual & Membership Benefit',
|
| 49 |
+
'Civil Rights, Social Action & Advocacy',
|
| 50 |
+
'Health Care',
|
| 51 |
+
'Animal-Related',
|
| 52 |
+
'Arts, Culture & Humanities',
|
| 53 |
+
'Recreation & Sports',
|
| 54 |
+
'Food, Agriculture & Nutrition',
|
| 55 |
+
],
|
| 56 |
+
'cause_area_secondary_class': [
|
| 57 |
+
'Hopsitals', #'Hopsitals', # NOTE THIS IS MISSPELLED IN THE API DATA -- 369 secondary matches
|
| 58 |
+
'Food, Agriculture & Nutrition',
|
| 59 |
+
'Community Improvement & Capacity Building',
|
| 60 |
+
'Mental Health & Crisis Intervention',
|
| 61 |
+
'Food, Agriculture & Nutrition',
|
| 62 |
+
'Housing & Shelter',
|
| 63 |
+
'Human Services',
|
| 64 |
+
'Arts, Culture & Humanities',
|
| 65 |
+
'Youth Development',
|
| 66 |
+
'Community Improvement & Capacity Building',
|
| 67 |
+
'Mutual & Membership Benefit',
|
| 68 |
+
'Civil Rights, Social Action & Advocacy',
|
| 69 |
+
'Health Care',
|
| 70 |
+
'Animal-Related',
|
| 71 |
+
'Arts, Culture & Humanities',
|
| 72 |
+
'Recreation & Sports',
|
| 73 |
+
'Food, Agriculture & Nutrition',
|
| 74 |
+
],
|
| 75 |
+
'locality': ['local state-wide', 'regional (multi-state)', 'international'],
|
| 76 |
+
'locality_by_grants': ['local/regional', 'national', 'international'],
|
| 77 |
+
'sdg': ['sdg1', 'sdg2', 'sdg3', 'sdg4', 'sdg5', 'sdg6', 'sdg7', 'sdg8', 'sdg9', 'sdg10', 'sdg11', 'sdg12', 'sdg13', 'sdg14', 'sdg15', 'sdg16'],
|
| 78 |
+
}
|
| 79 |
+
binary_fields = [
|
| 80 |
+
'opencorporates_matched',
|
| 81 |
+
'url200',
|
| 82 |
+
'local_place_based_org',
|
| 83 |
+
'is_a_community_foundation',
|
| 84 |
+
'org_religious_affiliation',
|
| 85 |
+
'org_mostly_supported_by_individuals',
|
| 86 |
+
'org_has_membership_dues',
|
| 87 |
+
'organization_supports_children',
|
| 88 |
+
'organization_supports_women',
|
| 89 |
+
'organization_supports_bipoc',
|
| 90 |
+
'organization_supports_elderly',
|
| 91 |
+
'organization_supports_low_income',
|
| 92 |
+
'organization_supports_disability',
|
| 93 |
+
'organization_supports_immigrants_refugees',
|
| 94 |
+
'organization_supports_lgbt',
|
| 95 |
+
'organization_supports_none_of_these_groups',
|
| 96 |
+
'pro_democracy_org',
|
| 97 |
+
'social_justice_human_rights_org',
|
| 98 |
+
'climate_change',
|
| 99 |
+
'has_revenue_model',
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
greater_than_fields = [
|
| 103 |
+
'cause_area_arts_culture_humanities', 'cause_area_education', 'cause_area_universities', 'cause_area_environment',
|
| 104 |
+
'cause_area_animal_related', 'cause_area_healthcare', 'cause_area_hospitals', 'cause_area_mental_health_crisis_intervention',
|
| 105 |
+
'cause_area_voluntary_health_associations_medical_disciplines', 'cause_area_medical_research', 'cause_area_crime_legal_related',
|
| 106 |
+
'cause_area_employment', 'cause_area_food_agriculture_nutrition', 'cause_area_housing_shelter',
|
| 107 |
+
'cause_area_public_safety_disaster_preparedness_relief', 'cause_area_recreation_sports', 'cause_area_youth_development',
|
| 108 |
+
'cause_area_human_services', 'cause_area_international_foreign_affairs_national_security',
|
| 109 |
+
'cause_area_civil_rights_social_action_advocacy', 'cause_area_community_improvement_capacity_building',
|
| 110 |
+
'cause_area_philanthropy_voluntarism_grantmaking_foundations', 'cause_area_science_technology', 'cause_area_social_science',
|
| 111 |
+
'cause_area_public_societal_benefit', 'cause_area_religion_related', 'cause_area_mutual_membership_benefit', 'cause_area_unknown',
|
| 112 |
+
'opencorporates_match_confidence',
|
| 113 |
+
]
|
| 114 |
+
less_than_fields = [
|
| 115 |
+
'acs_fraction_poverty', 'acs_fraction_snap', 'acs_fraction_insured', 'acs_median_income', 'acs_fraction_hs', 'acs_fraction_vacant', 'acs_dep_index',
|
| 116 |
+
|
| 117 |
+
'mapagora_BROAD', 'mapagora_REMNRTY',
|
| 118 |
+
'mapagora_POV150', 'mapagora_NOHSDP', 'mapagora_SNGPNT', 'mapagora_UNEMP', 'mapagora_civic_org_sum_normalized', 'mapagora_civic_opp_sum_normalized',
|
| 119 |
+
'mapagora_civic_opp_index', 'mapagora_volunteer_sum_normalized', 'mapagora_membership_sum_normalized', 'mapagora_take_action_sum_normalized', 'mapagora_events_sum_normalized',
|
| 120 |
+
'staff_gender_male_fraction', 'staff_gender_female_fraction',
|
| 121 |
+
'cause_area_animal_related',
|
| 122 |
+
]
|
| 123 |
+
less_than_int_fields = {
|
| 124 |
+
'mapagora_totalpopulation':50000,
|
| 125 |
+
'mapagora_n':3, 'mapagora_civic_org_sum':500, 'mapagora_civic_opp_sum':100,
|
| 126 |
+
'mapagora_volunteer_sum':150, 'mapagora_membership_sum':600,
|
| 127 |
+
'mapagora_take_action_sum':50, 'mapagora_events_sum':175,
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
def test_one(field, label=None):
|
| 131 |
+
if label and isinstance(label, (int,float)):
|
| 132 |
+
req = f"{endpoint}?key={key}&taxyear=2023&{field}={label}"
|
| 133 |
+
elif label:
|
| 134 |
+
req = f"{endpoint}?key={key}&taxyear=2023&{field}={urllib.parse.quote(label)}"
|
| 135 |
+
else:
|
| 136 |
+
req = f"{endpoint}?key={key}&taxyear=2023&{field}=1"
|
| 137 |
+
resp = r.get(req)
|
| 138 |
+
resp = resp.json()
|
| 139 |
+
if resp.get('success'):
|
| 140 |
+
if label:
|
| 141 |
+
print(f"{resp['params']}, {label} | {len(resp['eins'])} eins")
|
| 142 |
+
else:
|
| 143 |
+
print(f"{resp['params']}, {len(resp['eins'])} eins")
|
| 144 |
+
else:
|
| 145 |
+
print(resp)
|
| 146 |
+
time.sleep(0.1)
|
| 147 |
+
|
| 148 |
+
for field,labels in test_strings.items(): # PASSED
|
| 149 |
+
for label in labels:
|
| 150 |
+
test_one(field, label)
|
| 151 |
+
for field in binary_fields: # PASSED
|
| 152 |
+
test_one(field)
|
| 153 |
+
for field, value in less_than_int_fields.items(): # PASSED
|
| 154 |
+
test_one(field, value)
|
| 155 |
+
for field in greater_than_fields: # PASSED
|
| 156 |
+
test_one(field, 0.7)
|
| 157 |
+
for field in less_than_fields: # PASSED
|
| 158 |
+
test_one(field, 0.3)
|
| 159 |
+
|