def validate_state(state):
    """
    Utility function that accepts any valid string representation of a US state and returns a normalized two
    character abbreviation of the state.
    
    :param state:
        Type: String
        Default: None
        Description: String representation of a US state
    
    :return:
        If a valid US state is found, the two character state abbreviation is returned.
        Otherwise, a ValueError is raised
    """
    zipcode_search = ZipcodeSearchEngine()
    try:
        state_zips = zipcode_search.by_state(state)
        if state:
            state = state_zips[0]
            return state.State
        else:
            raise ValueError(
                'Could not find a valid US state with the given input: {}'.
                format(state))
    except TypeError:
        raise ValueError(
            'Could not find a valid US state with the given input: {}'.format(
                state))
def get_zip_codes_map():
    search = ZipcodeSearchEngine()
    zipcodes = list()
    for state in get_states():
        # for state in ['New York']:
        final_response = list()
        response = search.by_state(state, returns=2000)
        for r in response:
            if r['City'] not in [x['City'] for x in final_response]:
                final_response.append(r)
        for res in response:
            if res:
                zipcodes.append({
                    'zip_code': res.Zipcode,
                    'latitude': res.Latitude,
                    'longitude': res.Longitude,
                    'city': res.City,
                    'state': res.State
                })
    return sorted(zipcodes, key=lambda k: k['state'])
api = Client(apikey)

# In[20]:

params = {'term': 'Indian', 'limit': 50, 'offset': 0}
val = api.business_search(location='New Jersey', **params)
df = json_normalize(val, 'businesses')
df2 = json_normalize(val)

# In[21]:

#pip.main(['install','uszipcode'])
from uszipcode import ZipcodeSearchEngine

search = ZipcodeSearchEngine()
res = search.by_state(state='New Jersey', returns=0)
resdf = json_normalize(res)

zcode = resdf[0]
za = zcode.values
zc = za[-10:].tolist()
zc

# In[23]:

mdf = pd.DataFrame()
for i in zc:
    params = {'term': 'Indian', 'limit': 50, 'offset': 0}
    val = api.business_search(location=i, **params)
    df = json_normalize(val)
    df2 = json_normalize(val, 'businesses')
Example #4
0
    ssn = prepare_ssn(df)

    clean_ssn(df, i, ssn)
    if len(zip) == 5:
        set_by_zip(zip, df, i)
    else:
        try:
            L_city = search._find_city(df['City'].values[i], best_match=True)
            df.iloc[i, df.columns.get_loc('City')] = L_city[0]
            res = search.by_city(L_city[0])
            if (len(res) == 0):
                try:
                    L_state = search._find_city(df['State'].values[i],
                                                best_match=True)
                    df.iloc[i, df.columns.get_loc('State')] = L_state[0]
                    res = search.by_state(L_state[0])
                    if (len(res) == 0):
                        set_unknown(df, i)
                    else:
                        set_by_state_and_city(res, L_state, df)
                except ValueError:
                    set_unknown(df, i)
            else:
                set_by_city(df, i, res)
        except ValueError:
            try:
                L_state = search._find_city(df['State'].values[i],
                                            best_match=True)
                df.iloc[i, df.columns.get_loc('State')] = L_state[0]
                res = search.by_state(L_state[0])
                if len(res) == 0:
Example #5
0
val
dd = json_normalize(val)
dd

dd.head(5)

df = json_normalize(val, 'businesses')
df.head()
df.columns

##package to get all the zipcodes
pip.main(['install', 'uszipcode'])
from uszipcode import ZipcodeSearchEngine

search = ZipcodeSearchEngine()
res = search.by_state(state='North Carolina', returns=0)
resdf = json_normalize(res)
resdf

zcode = resdf[0]
za = zcode.values
za
zc = za[-10:].tolist()
zc
zc.append('28208')
zc
zc = zc[-1]
zc
mdf = pd.DataFrame()
for i in zc:
    params = {'term': 'Mexican', 'limit': 50, 'offset': 0}
Example #6
0
# data setup
db = MySQLdb.connect(
    host="localhost",  # your host, usually localhost
    user="******",  # your username
    passwd="AshPon",  # your password
    db="where_are_your_stores")  # name of the data base

cur = db.cursor()

sqlStr = ("SELECT njstores.LOCATION_NAME,\
	              njstores.CITY_NAME  \
	         FROM where_are_your_stores.njstores")

# define search object for uszips
search = ZipcodeSearchEngine()
zipcode = search.by_state('New Jersey', returns=0)
# print(zipcode)

# for aRec in zipcode:
# 	print (aRec)


# start the engine
@app.route("/")
def homepage():
    return render_template("index.html")


# define a route called by index and base js
# this route will return all the stores information from the file in a list
# the file I loaded I will convert it into a list and return it