Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def find_state_from_coords(lat, long) -> str:
"""
determines the US state based on a particular set of coordinates
"""
with ZipcodeSearchEngine() as search:
res = search.by_coordinate(lat, long, radius=30)
if not res:
return None
# get zipcode based on lat / long
zipcode = res[0]['Zipcode']
print(zipcode)
if not zipcode:
return None
# use zipcode object to determine state
zipcode_object = search.by_zipcode(zipcode)
text = name_object.get_text()
user.set_email(get_email(text))
if not phone_flag and not neighbor == None:
user.set_phone(get_cell(neighbor.get_text()))
else:
name_object = text_prop_dict.get(top_text_id)
text = name_object.get_text()
user.set_phone(get_cell(text))
if not neighbor == None:
zipcode = get_zipcode(neighbor.get_text())
# Use zipcode dictionary to find state and city
search = ZipcodeSearchEngine()
zip_obj = search.by_zipcode(zipcode)
state = zip_obj.State
city = zip_obj.City
user.set_addr(None,city, state, "USA", zipcode)
if not link_flag and not neighbor == None:
user.set_link(get_links(neighbor.get_text()))
else:
name_object = text_prop_dict.get(top_text_id)
text = name_object.get_text()
user.set_link(get_links(text))
# user.display()
# show_object(neighbor)
return user
from uszipcode import ZipcodeSearchEngine
from math import radians, cos, sin, asin, sqrt
import math
import os
search = ZipcodeSearchEngine()
res = search.by_coordinate(39.122229, -77.133578, radius=30000, returns=5000000)
# This returns every us zip code
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2