<jupyter_start><jupyter_text>Amenity to get   - clinic- doctors- hospital- pharmacy<jupyter_code>import requests
import json

import pandas as pd
import time
overpass_url = "http://overpass-api.de/api/interpreter"
overpass_query = """
[out:json];
area["ISO3166-1"="DO"][admin_level=2];
(node["amenity"="hospital"](area);
 way["amenity"="hospital"](area);
 rel["amenity"="hospital"](area);
);
out center;
"""
response = requests.get(overpass_url, 
                        params={'data': overpass_query})
data = response.json()
data
data.keys()
data['elements']
len(data['elements'])
data['elements'][0].keys()
data['elements'][0]['tags']
data['elements'][0]['tags']['name']
country, type_, lat, lon, categ, name = [], [], [], [], [], []
for element in data['elements']:
    country.append('DO')
    type_.append(element['type'])
    lat.append(element['lat'])
    lon.append(element['lon'])
    categ.append(element['tags']['amenity'])
    if 'name' in element['tags'].keys():
        name.append(element['tags']['name'])
    else:
        name.append('unknown name')
data['elements'][7]#['tags']
len(name)
amenity_list = ['hospital', 'clinic', 'doctors', 'pharmacy']
country, type_, lat, lon, categ, name = [], [], [], [], [], []

for amen in amenity_list[:2]:    
    overpass_url = "http://overpass-api.de/api/interpreter"
    overpass_query = f'[out:json][timeout:25];area["ISO3166-1"="DO"][admin_level=2];(node["amenity"={amen}](area);way["amenity"={amen}](area);rel["amenity"={amen}](area););out center;'
    
    response = requests.get(overpass_url, 
                            params={'data': overpass_query})
    data = response.json()
    print(amen)
    
    for element in data['elements']:
        country.append('DO')
        type_.append(element['type'])
        lat.append(element['lat'])
        lon.append(element['lon'])
        categ.append(element['tags']['amenity'])
        if 'name' in element['tags'].keys():
            name.append(element['tags']['name'])
        else:
            name.append('unknown name')
    time.sleep(2)
amenity_list = ['hospital', 'clinic', 'doctors', 'pharmacy']
country, type_, lat, lon, categ, name = [], [], [], [], [], []

for amen in amenity_list[2:]:    
    overpass_url = "http://overpass-api.de/api/interpreter"
    overpass_query = f'[out:json][timeout:25];area["ISO3166-1"="DO"][admin_level=2];(node["amenity"={amen}](area);way["amenity"={amen}](area);rel["amenity"={amen}](area););out center;'
    
    response = requests.get(overpass_url, 
                            params={'data': overpass_query})
    data = response.json()
    print(amen)
    
    for element in data['elements']:
        country.append('DO')
        type_.append(element['type'])
        lat.append(element['lat'])
        lon.append(element['lon'])
        categ.append(element['tags']['amenity'])
        if 'name' in element['tags'].keys():
            name.append(element['tags']['name'])
        else:
            name.append('unknown name')
    time.sleep(2)
df = pd.DataFrame({'Name':name, 'Type':type_, 'Category':categ, 'Country':country, 'lat':lat, 'lon':lon})
df.tail()
len(name)
df.describe(include='all')
df['test'] = df.lat.astype('str') + ' / ' + df.lon.astype('str')
df[df.test.duplicated(keep=False)].groupby(['test','Name','Category']).count()<jupyter_output><empty_output><jupyter_text>pd.set_option('display.max_rows',None)<jupyter_code>df.Name.value_counts()
df[df.Name == 'Farmacia']
df[df.Name == 'Hospital Municipal']
df[df.Name == 'International Medical Center']
df[df.Name == '<NAME>']
df[df.Name == 'Hospital IDSS']
df[df.Name == 'unknown name']
df.dtypes
df.info()
df.head()<jupyter_output><empty_output><jupyter_text>---  Haiti<jupyter_code>#amenity_list = ['hospital', 'clinic', 'doctors', 'pharmacy']
country_ht, type_ht, lat_ht, lon_ht, categ_ht, name_ht = [], [], [], [], [], []

for amen in amenity_list[:2]:    
    overpass_url = "http://overpass-api.de/api/interpreter"
    overpass_query = f'[out:json][timeout:25];area["ISO3166-1"="HT"][admin_level=2];(node["amenity"={amen}](area);way["amenity"={amen}](area);rel["amenity"={amen}](area););out center;'
    
    response_ht = requests.get(overpass_url, 
                            params={'data': overpass_query},timeout=10)
    data_ht = response_ht.json()
    
    print('------------------------------------'+amen)
    
    for element in data_ht['elements']:
        country_ht.append('HT')
        type_ht.append(element['type'])
        lat_ht.append(element['lat'])
        lon_ht.append(element['lon'])
        categ_ht.append(element['tags']['amenity'])
        if 'name' in element['tags'].keys():
            name_ht.append(element['tags']['name'])
            print(element['tags']['name'])
        else:
            name_ht.append('unknown name')
            print('Unknown')
    time.sleep(2)
        
#amenity_list = ['hospital', 'clinic', 'doctors', 'pharmacy']
country_ht, type_ht, lat_ht, lon_ht, categ_ht, name_ht = [], [], [], [], [], []

for amen in amenity_list[2:]:    
    overpass_url = "http://overpass-api.de/api/interpreter"
    overpass_query = f'[out:json][timeout:25];area["ISO3166-1"="HT"][admin_level=2];(node["amenity"={amen}](area);way["amenity"={amen}](area);rel["amenity"={amen}](area););out center;'
    
    response_ht = requests.get(overpass_url, 
                            params={'data': overpass_query},timeout=10)
    data_ht = response_ht.json()
    
    print('------------------------------------'+amen)
    
    for element in data_ht['elements']:
        country_ht.append('HT')
        type_ht.append(element['type'])
        lat_ht.append(element['lat'])
        lon_ht.append(element['lon'])
        categ_ht.append(element['tags']['amenity'])
        if 'name' in element['tags'].keys():
            name_ht.append(element['tags']['name'])
            print(element['tags']['name'])
        else:
            name_ht.append('unknown name')
            print('Unknown')
    time.sleep(2)<jupyter_output>------------------------------------doctors
Clinic
Clinic <NAME>
Unknown
Unknown
Unknown
Unknown
Unknown
Unknown
Unknown
Unknown
l'Arche des Enfants
mayte
Unknown
Clinique Saint Soleil
Centre de Santé Familiale
complexe medico-chirurgical,bon samaritain
clinique medical
Sant medical Santo 20
Obstetrique-Gynecologue
Clinique Medico Docteur Claupha
Centre Medical Joseph Edmond et Pharmacie
Clinipharma Ma sante
Clinique Beaulieu
Clinique medicale Chirurgicale et Steri Lab Laboratoire medical
Dental office Radiographie
MEDITEL SA
Unknown
Le Pivert
<NAME>
FEBS
Fondation <NAME>
Constitution Mertenal
Constitution Mertenal
Unknown
International Medical Corps
Clinique Medicale de Saint-Marc
Ministere de la sante publique
CERBIO-LAB
Cadiolab Laboratoire Graphtech
Unknown
FEBS
Optimed Clinique
M et M
Clinique Revolution De Bois Bouton
Centre Me
Clinic City Med Cayes
Unknown
Dispanse Kominote Senate Polycap
Dispanse Bonami
Dispasè kominote Doktè Policap Souffri[...]<jupyter_text>for el in data['elements']:    print (el['tags']['name'])<jupyter_code>df_ht = pd.DataFrame({'Name':name_ht, 'Type':type_ht, 'Category':categ_ht, 'Country':country_ht, 'lat':lat_ht, 'lon':lon_ht})
df_ht.tail()
df_ht.shape
df_ht.lon.nunique()
df_ht['test'] = '(' + df_ht.lat.astype('str') + ' ; ' + df_ht.lon.astype('str') + ')'
df_ht.head()
df_ht.loc[880:889,:]
df_ht.test.nunique()
df_ht.test.value_counts()
df_ht[df_ht.test.duplicated(keep=False)].groupby(['test','Name','Category']).count().drop(['Type','Country','lat','lon'], axis=1)
df.to_csv(r'../output/dom_healthsites_1.csv',index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20005264543300869, 'fraction_numerical': 0.008423269281389839, 'mean_word_length': 3.9699149771092217, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '158394', 'license': 'MIT', 'n_tokens_mistral': 2621, 'n_tokens_neox': 2570, 'n_words': 425, 'path': 'Notebooks/OSM_api.ipynb', 'repo_name': 'weinerkervens/Ayiti_Analytics_Capstone_Project', 'size': '7638'}