Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def by_pattern(self,
pattern,
zipcode_type=ZipcodeType.Standard,
sort_by=SimpleZipcode.zipcode.name,
ascending=True,
returns=DEFAULT_LIMIT):
"""
Search zipcode by wildcard.
Returns multiple results.
"""
return self.query(
pattern=pattern,
sort_by=sort_by, zipcode_type=zipcode_type,
ascending=ascending, returns=returns,
)
from uszipcode.model import Base, Zipcode, SimpleZipcode, _simple_zipcode_columns
from uszipcode.db import connect_to_simple_zipcode_db, connect_to_zipcode_db
simple_zipcode_engine = connect_to_simple_zipcode_db()
Base.metadata.create_all(simple_zipcode_engine)
zipcode_engine = connect_to_zipcode_db()
zipcode_ses = sessionmaker(bind=zipcode_engine)()
selected_columns = [
getattr(Zipcode, name)
for name in _simple_zipcode_columns
]
simple_zipcode_data = list()
for data_tuple in zipcode_ses.query(*selected_columns):
simple_zipcode = SimpleZipcode(**dict(list(zip(_simple_zipcode_columns, data_tuple))))
simple_zipcode_data.append(simple_zipcode)
SimpleZipcode.smart_insert(simple_zipcode_engine, simple_zipcode_data)
def __init__(self, simple_zipcode=True, db_file_dir=HOME_USZIPCODE):
Path(db_file_dir).mkdir(exist_ok=True)
if simple_zipcode:
if not is_simple_db_file_exists(db_file_dir):
download_simple_db_file(db_file_dir)
engine = connect_to_simple_zipcode_db(db_file_dir)
self.zip_klass = SimpleZipcode
else: # pragma: no cover
if not is_db_file_exists(db_file_dir):
download_db_file(db_file_dir)
engine = connect_to_zipcode_db(db_file_dir)
self.zip_klass = Zipcode
self.engine = engine
self.ses = sessionmaker(bind=engine)()
simple_zipcode_engine = connect_to_simple_zipcode_db()
Base.metadata.create_all(simple_zipcode_engine)
zipcode_engine = connect_to_zipcode_db()
zipcode_ses = sessionmaker(bind=zipcode_engine)()
selected_columns = [
getattr(Zipcode, name)
for name in _simple_zipcode_columns
]
simple_zipcode_data = list()
for data_tuple in zipcode_ses.query(*selected_columns):
simple_zipcode = SimpleZipcode(**dict(list(zip(_simple_zipcode_columns, data_tuple))))
simple_zipcode_data.append(simple_zipcode)
SimpleZipcode.smart_insert(simple_zipcode_engine, simple_zipcode_data)
:param median_household_income: int,
:param bounds_west: number,
:param bounds_east: number,
:param bounds_north: number,
:param bounds_south: number,
"""
__tablename__ = "simple_zipcode"
__mapper_args__ = {
"polymorphic_identity": "simple_zipcode",
}
_simple_zipcode_columns = [c.name for c in SimpleZipcode.__table__.columns]
class Zipcode(BaseZipcode):
"""
Zipcode that with rich info.
:param population_by_year: population change over year.
:param population_by_age: population distribution by gender and age.
:param population_by_gender: population distribution by gender.
:param population_by_race: population distribution by race.
:param head_of_household_by_age: head of household distribution by age.
:param families_vs_singles: population distribution by marital status.
:param households_with_kids: population by with or without kids.
:param children_by_age: children population distribution by age
:param housing_type: number of house distribution of house type.