Skip to content

Commit 53f37b9

Browse files
authored
Merge pull request #30 from DovetailJohn/configurable_remote_sqlite_download_path
allow the sqlite download url to be specified via init
2 parents 59d9bd9 + 2b88ba5 commit 53f37b9

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

uszipcode/db.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from uszipcode.pkg.atomicwrites import atomic_write
2424
from uszipcode.pkg.sqlalchemy_mate import engine_creator
2525

26+
SIMPLE_DB_FILE_DOWNOAD_URL = "https://datahub.io/machu-gwu/uszipcode-0.2.0-simple_db/r/simple_db.sqlite"
27+
DB_FILE_DOWNOAD_URL = "https://datahub.io/machu-gwu/uszipcode-0.2.0-db/r/db.sqlite"
2628

2729
def get_simple_db_file_path(db_file_dir):
2830
return Path(db_file_dir, "simple_db.sqlite")
@@ -58,8 +60,8 @@ def connect_to_zipcode_db(db_file_dir):
5860
path=get_db_file_path(db_file_dir).abspath)
5961

6062

61-
def download_simple_db_file(db_file_dir):
62-
simple_db_file_download_url = "https://datahub.io/machu-gwu/uszipcode-0.2.0-simple_db/r/simple_db.sqlite"
63+
def download_simple_db_file(db_file_dir, download_url=None):
64+
simple_db_file_download_url = download_url if download_url else SIMPLE_DB_FILE_DOWNOAD_URL
6365

6466
if not is_simple_db_file_exists(db_file_dir):
6567
print("Start downloading data for simple zipcode database, total size 9MB ...")
@@ -77,8 +79,9 @@ def download_simple_db_file(db_file_dir):
7779
print(" Complete!")
7880

7981

80-
def download_db_file(db_file_dir):
81-
db_file_download_url = "https://datahub.io/machu-gwu/uszipcode-0.2.0-db/r/db.sqlite"
82+
def download_db_file(db_file_dir, download_url=None):
83+
db_file_download_url = download_url if download_url else DB_FILE_DOWNOAD_URL
84+
8285
if not is_db_file_exists(db_file_dir):
8386
print(
8487
"Start downloading data for rich info zipcode database, total size 450+MB ...")

uszipcode/search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ class SearchEngine(object):
8585
_state_to_city_mapper = None
8686
_city_to_state_mapper = None
8787

88-
def __init__(self, simple_zipcode=True, db_file_dir=HOME_USZIPCODE):
88+
def __init__(self, simple_zipcode=True, db_file_dir=HOME_USZIPCODE, download_url=None):
8989
Path(db_file_dir).mkdir(exist_ok=True)
9090

9191
if simple_zipcode:
9292
if not is_simple_db_file_exists(db_file_dir):
93-
download_simple_db_file(db_file_dir)
93+
download_simple_db_file(db_file_dir, download_url=download_url)
9494
engine = connect_to_simple_zipcode_db(db_file_dir)
9595
self.zip_klass = SimpleZipcode
9696
else: # pragma: no cover
9797
if not is_db_file_exists(db_file_dir):
98-
download_db_file(db_file_dir)
98+
download_db_file(db_file_dir, download_url=download_url)
9999
engine = connect_to_zipcode_db(db_file_dir)
100100
self.zip_klass = Zipcode
101101
self.engine = engine

0 commit comments

Comments
 (0)