<commit_before>#!/usr/bin/python3
# -*- coding: utf-8 -*-
# location_data.py

import requests
import pprint
import os

lst = ['Glenelg Jetty', 'Sydney Opera House', 'Uluru', 'New York,Central Park','Zimbabwe,Victoria Falls','1 King William St, Adelaide, Australia'] 

"""
lst = []
with open(os.path.join(os.getcwd(),'..','..','..','test','list_names_to_lookup.txt')) as f:
    for line in f:
        lst.append(line.strip('\n'))
"""        


base_url = 'https://maps.googleapis.com/maps/api/geocode/json?'

raw_json_file = 'json_raw.txt'
if os.path.exists(raw_json_file):
    os.remove(raw_json_file)

def main():
    res = '"search_term","result_num","gps_lat","gps_lng","formatted_address",\n'
    for name in lst:
        try:
            res += lookup_address(name)
        except Exception as ex:
            print('missing data for ', name)
    with open('address.csv', 'w') as f:
        f.write(res)
    print('Done')

def lookup_address(nme):
    """
    use the Google map API to get address details
    """
    csv_line = ''        
    response = requests.get(base_url + 'address=' + nme)

    resp_json_payload = response.json()
    with open(raw_json_file, 'a') as f_raw:
        try:
            pprint.pprint(resp_json_payload, stream=f_raw)
        except Exception as ex:<commit_msg>uses file in test folder if available<commit_after>#!/usr/bin/python3
# -*- coding: utf-8 -*-
# location_data.py

import requests
import pprint
import os

src_file = os.path.join(os.getcwd(),'..','..','..','test','list_names_to_lookup.txt')
if os.path.exists(src_file):
    lst = []
    with open(src_file, 'r') as f:
        for line in f:
            lst.append(line.strip('\n'))
else:
    lst = ['Glenelg Jetty', 'Sydney Opera House', 'Uluru', 'New York,Central Park','Zimbabwe,Victoria Falls','1 King William St, Adelaide, Australia'] 
     


base_url = 'https://maps.googleapis.com/maps/api/geocode/json?'

raw_json_file = 'json_raw.txt'
if os.path.exists(raw_json_file):
    os.remove(raw_json_file)

def main():
    res = '"search_term","result_num","gps_lat","gps_lng","formatted_address",\n'
    for name in lst:
        try:
            res += lookup_address(name)
        except Exception as ex:
            print('missing data for ', name)
    with open('address.csv', 'w') as f:
        f.write(res)
    print('Done')

def lookup_address(nme):
    """
    use the Google map API to get address details
    """
    csv_line = ''        
    response = requests.get(base_url + 'address=' + nme)

    resp_json_payload = response.json()
    with open(raw_json_file, 'a') as f_raw:
        try:
            pprint.pprint(resp_json_payload, stream=f_raw)
        except Exception as ex:
{'fraction_non_alphanumeric': 0.1549870226177234, 'fraction_numerical': 0.002224694104560623, 'mean_word_length': 2.997037037037037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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}}
{'dir': 'git-commits-cleaned', 'id': '1340850', 'n_tokens_mistral': 951, 'n_tokens_neox': 924, 'n_words': 209}