<jupyter_start><jupyter_text>Appendix: census.ire.org<jupyter_code># can we use http://census.ire.org/docs/boundary.html to locate Cafe Milano
# http://geocoder.us/

import requests

try:
    from urllib.parse import urlparse, urlencode, parse_qs, urlunparse
except ImportError:
    from urlparse import urlparse, parse_qs, urlunparse
    from urllib import urlencode
    
    
def geocoder_us(address="1600 Pennsylvania Ave, Washington, DC"):
    """takes an adddress and returns the the result of a geocoding call to geocoder.us"""
    base_url = "http://rpc.geocoder.us/service/json"
    url = base_url + "?" + urlencode({'address':address})
    return requests.get(url).json()

r = geocoder_us('2522 Bancroft Way, BERKELEY, CA, 94704')
r
# let's try the census.ire.org service...which we can host ourselves soon
# http://census.ire.org/docs/boundary.html
# at least down to the tract
# http://census.ire.org/geo/1.0/boundary/?contains=38.948337,-92.328032&sets=tracts,counties



def ire_contains(lat,lng,sets=None):

    if sets is None:
        sets1 = ["tracts","counties"]
    else:
        sets1 = sets
    base_url = "http://census.ire.org/geo/1.0/boundary/"
    url = base_url + "?" + urlencode(
        {
          'contains': "{lat},{lng}".format(lat=lat, lng=lng),
          'sets': sets1
        },
        True
     )

    return requests.get(url).json()
    

response = ire_contains(lat=r[0]['lat'],lng=r[0]['long'])
response<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1425661914460285, 'fraction_numerical': 0.025797691785471828, 'mean_word_length': 3.4531722054380665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '343602', 'license': 'Apache-2.0', 'n_tokens_mistral': 547, 'n_tokens_neox': 517, 'n_words': 113, 'path': 'zzz-ire.ipynb', 'repo_name': 'rdhyee/diversity-census-calc', 'size': '1473'}