Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ipinfo_db/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ def __init__(self, access_token=None, path=None, replace=False):
self.path = DEFAULT_DB_PATH

# Check if file already exists to skip the download.
if os.path.exists(self.path) and not self.replace:
if os.path.isfile(self.path) and not self.replace:
pass
else:
if self.access_token is None:
raise SyntaxError("Token is required to download the file")

# Create directory if doesn't exist and download file.
# Create directory if doesn't exist.
directory = os.path.dirname(self.path)
if directory and not os.path.exists(directory):
os.makedirs(directory)
urllib.request.urlretrieve(DB_DOWNLOAD_URL+self.access_token, self.path)

# Download file.
urllib.request.urlretrieve(DB_DOWNLOAD_URL+self.access_token, self.path)

# Read the mmdb file.
self.db = maxminddb.open_database(self.path)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
author_email="support@ipinfo.io",
license="Apache License 2.0",
packages=["ipinfo_db"],
install_requires=["maxminddb"],
install_requires=["maxminddb", "appdirs"],
include_package_data=True,
zip_safe=False,
)