sibi-dst 0.3.28__tar.gz → 0.3.29__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/PKG-INFO +1 -1
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/pyproject.toml +1 -1
- sibi_dst-0.3.29/sibi_dst/geopy_helper/__init__.py +7 -0
- sibi_dst-0.3.29/sibi_dst/geopy_helper/geo_location_service.py +63 -0
- sibi_dst-0.3.29/sibi_dst/geopy_helper/utils.py +55 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/README.md +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/_df_helper.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/_parquet_artifact.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/_parquet_reader.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/django/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/django/_db_connection.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/django/_io_dask.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/django/_load_from_db.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/django/_sql_model_builder.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/http/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/http/_http_config.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/parquet/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/parquet/_filter_handler.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/parquet/_parquet_options.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/_db_connection.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/_filter_handler.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/_io_dask.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/_load_from_db.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/_sql_model_builder.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/core/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/core/_defaults.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/core/_filter_handler.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/core/_params_config.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/core/_query_config.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/data_cleaner.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/osmnx_helper/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/osmnx_helper/base_osm_map.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/osmnx_helper/basemaps/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/osmnx_helper/basemaps/calendar_html.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/osmnx_helper/basemaps/router_plotter.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/osmnx_helper/utils.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/tests/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/tests/test_data_wrapper_class.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/__init__.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/airflow_manager.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/clickhouse_writer.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/credentials.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/data_utils.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/data_wrapper.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/date_utils.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/df_utils.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/file_utils.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/filepath_generator.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/log_utils.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/parquet_saver.py +0 -0
- {sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/utils/storage_manager.py +0 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
import os
|
2
|
+
from urllib.parse import urlparse
|
3
|
+
from geopy.geocoders import Nominatim
|
4
|
+
from geopy.exc import GeocoderTimedOut, GeocoderServiceError
|
5
|
+
|
6
|
+
app_nominatim_url = os.environ.get('NOMINATIM_URL', None)
|
7
|
+
app_geo_locator_test_place = os.environ.get('GEO_LOCATOR_TEST_PLACE', "San Jose, Costa Rica")
|
8
|
+
|
9
|
+
|
10
|
+
class GeolocationService:
|
11
|
+
debug: bool = False
|
12
|
+
|
13
|
+
def __init__(self, debug=False):
|
14
|
+
self.geolocator = None
|
15
|
+
self._initialize_geolocator()
|
16
|
+
self.debug = debug
|
17
|
+
|
18
|
+
def _initialize_geolocator(self):
|
19
|
+
nominatim_url = app_nominatim_url
|
20
|
+
if not nominatim_url:
|
21
|
+
if self.debug:
|
22
|
+
print("Nominatim URL not provided in environment variables.")
|
23
|
+
return
|
24
|
+
|
25
|
+
try:
|
26
|
+
parsed_url = urlparse(nominatim_url)
|
27
|
+
nominatim_url = parsed_url.netloc
|
28
|
+
self.geolocator = Nominatim(user_agent="ibis", scheme="http", domain=nominatim_url)
|
29
|
+
|
30
|
+
# Test the geolocator to ensure it is available
|
31
|
+
location = self.geolocator.geocode(app_geo_locator_test_place)
|
32
|
+
if location:
|
33
|
+
if self.debug:
|
34
|
+
print("Geolocator is available.")
|
35
|
+
else:
|
36
|
+
if self.debug:
|
37
|
+
print("Geolocator service is not responding correctly.")
|
38
|
+
self.geolocator = None
|
39
|
+
except (GeocoderTimedOut, GeocoderServiceError) as e:
|
40
|
+
print(f"Error initializing geolocator: {e}")
|
41
|
+
self.geolocator = None
|
42
|
+
|
43
|
+
def geocode(self, address):
|
44
|
+
if not self.geolocator:
|
45
|
+
if self.debug:
|
46
|
+
print("Geolocator is not available.")
|
47
|
+
return None
|
48
|
+
try:
|
49
|
+
return self.geolocator.geocode(address)
|
50
|
+
except (GeocoderTimedOut, GeocoderServiceError) as e:
|
51
|
+
print(f"Error during geocoding: {e}")
|
52
|
+
return None
|
53
|
+
|
54
|
+
def reverse(self, coordinates, exactly_one=True):
|
55
|
+
if not self.geolocator:
|
56
|
+
if self.debug:
|
57
|
+
print("Geolocator is not available.")
|
58
|
+
return None
|
59
|
+
try:
|
60
|
+
return self.geolocator.reverse(coordinates, exactly_one=exactly_one)
|
61
|
+
except (GeocoderTimedOut, GeocoderServiceError) as e:
|
62
|
+
print(f"Error during reverse geocoding: {e}")
|
63
|
+
return None
|
@@ -0,0 +1,55 @@
|
|
1
|
+
from .geo_location_service import GeolocationService, GeocoderTimedOut, GeocoderServiceError
|
2
|
+
|
3
|
+
# Initialize the geolocator once
|
4
|
+
geolocator = None
|
5
|
+
|
6
|
+
|
7
|
+
def get_geolocator():
|
8
|
+
global geolocator
|
9
|
+
if geolocator is None:
|
10
|
+
geolocator = GeolocationService(debug=True)
|
11
|
+
return geolocator
|
12
|
+
|
13
|
+
|
14
|
+
#geolocator = GeolocationService(debug=True)
|
15
|
+
|
16
|
+
|
17
|
+
def get_address_by_coordinates(latitude, longitude, exactly_one=True):
|
18
|
+
geolocator = get_geolocator()
|
19
|
+
try:
|
20
|
+
location = geolocator.reverse((latitude, longitude), exactly_one=exactly_one)
|
21
|
+
if not location:
|
22
|
+
return "No address found for this location."
|
23
|
+
address = location.address
|
24
|
+
return address
|
25
|
+
except GeocoderTimedOut:
|
26
|
+
return "GeocoderTimedOut: Failed to reach the server."
|
27
|
+
|
28
|
+
|
29
|
+
def get_coordinates_for_address(address):
|
30
|
+
"""
|
31
|
+
Geocode an address using a custom Nominatim server.
|
32
|
+
|
33
|
+
:param address: The address to geocode.
|
34
|
+
:return: A dictionary with the location's latitude, longitude, and full address, or a message if an error occurs.
|
35
|
+
"""
|
36
|
+
geolocator = get_geolocator()
|
37
|
+
try:
|
38
|
+
location = geolocator.geocode(address)
|
39
|
+
|
40
|
+
# Check if location was found
|
41
|
+
if location:
|
42
|
+
return {
|
43
|
+
"Address": location.address,
|
44
|
+
"Latitude": location.latitude,
|
45
|
+
"Longitude": location.longitude
|
46
|
+
}
|
47
|
+
else:
|
48
|
+
return "Location not found."
|
49
|
+
|
50
|
+
except GeocoderTimedOut:
|
51
|
+
return "GeocoderTimedOut: Request timed out."
|
52
|
+
except GeocoderServiceError as e:
|
53
|
+
return f"GeocoderServiceError: {str(e)}"
|
54
|
+
except Exception as e:
|
55
|
+
return f"Error: {str(e)}"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/django/_sql_model_builder.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/_db_connection.py
RENAMED
File without changes
|
{sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/_filter_handler.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{sibi_dst-0.3.28 → sibi_dst-0.3.29}/sibi_dst/df_helper/backends/sqlalchemy/_sql_model_builder.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|