geolocate.classes.geowrapper module

geolocate wrapper to Geolite2 API.

Programmed by: Dante Signal31

email: dante.signal31@gmail.com

exception geolocate.classes.geowrapper.CompressedFileNotFound(compressed_database_path)[source]

Bases: OSError

Raised when no .gz compressed file is found in temporary folder where downloaded data is placed.

__init__(compressed_database_path)[source]
exception geolocate.classes.geowrapper.GeoIP2WebServiceNotConfigured[source]

Bases: Exception

GeoIP2 WebService access is still not configured.

__init__()[source]
class geolocate.classes.geowrapper.GeoIPDatabase(configuration)[source]

Bases: object

Location engines may have multiple query methods. This class encapsulates them all in _locators list.

__init__(configuration)[source]
Parameters:configuration (config.Configuration) – Geolocate configuration.
geoip2_local
geoip2_webservice
Returns:GeoIPLocateor to query GeoIP webservice.
Return type:WebServiceGeoLocator
Raises:GeoIP2WebServiceNotConfigured
locate(ip)[source]

Query enabled locators in preference order until getting any geodata.

Parameters:ip (IP address string.) – IP address to look for.
Returns:Location data for that address.
Return type:geoip2.models.City
class geolocate.classes.geowrapper.GeoLocator(configuration)[source]

Bases: object

__init__(configuration)[source]
locate(ip)[source]

Get geolocation data from database.

Parameters:ip (str) – IP address we are asking about.
Raises:geoip2.errors.AddressNotFoundError
Returns:Geolocation data.
Return type:geoip2.models.City
exception geolocate.classes.geowrapper.InvalidLocalDatabase(local_database_path)[source]

Bases: Exception

Local database exists but is corrupted.

__init__(local_database_path)[source]
class geolocate.classes.geowrapper.LocalDatabaseGeoLocator(configuration)[source]

Bases: geolocate.classes.geowrapper.GeoLocator

__init__(configuration)[source]
Parameters:configuration (config.Configuration) – Geolocate configuration.
Returns:none
Raise:LocalDatabaseNotFound
Raise:InvalidLocalDatabase
exception geolocate.classes.geowrapper.LocalDatabaseNotFound(local_database_path)[source]

Bases: OSError

Local database file is missing.

__init__(local_database_path)[source]
exception geolocate.classes.geowrapper.NotValidDatabaseFileFound(decompressed_database_path)[source]

Bases: OSError

Raised when a new database pack is downloaded on local, but after decompression no valid database file is found in decompressed folder.

__init__(decompressed_database_path)[source]
class geolocate.classes.geowrapper.WebServiceGeoLocator(configuration)[source]

Bases: geolocate.classes.geowrapper.GeoLocator

__init__(configuration)[source]
Parameters:configuration (config.Configuration) – Geolocate configuration.
Returns:None
geolocate.classes.geowrapper.load_geoip_database(configuration=None)[source]