lee - snowpark_geolocator modified

This commit is contained in:
Yam ZhengLim
2023-05-10 09:12:31 +00:00
parent dbe3c1f716
commit 8bcace6545
2 changed files with 29 additions and 6 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
# DBT governance
Thid markdown document will specify the rules that need to follow by every developer.
This markdown document will specify the rules that need to follow by every developer.
<br>
Short naming converntion lists that need to follow
Short naming convention lists that need to follow
| model_type Shortcut | Full name |
| ------------------- | ------ |
+27 -4
View File
@@ -1,6 +1,29 @@
# snowpark start here
def model(dbt, session):
# Import libraries
# Basic Snowpark API available
# https://docs.snowflake.com/developer-guide/snowpark/reference/python/index.html
from snowflake import *
from geopy.geocoders import Nominatim
import requests
my_sql_model_df = dbt.ref("test_address__mock_data")
# Initialize geopy geolocator using Nominatim (OpenStreetMap)
geolocator = Nominatim(user_agent="cief_geolocator")
# Function to geocode address and return latitude and longitude
def geocode_address(address):
location = geolocator.geocode(address)
if location:
return (location.latitude, location.longitude)
else:
return (None, None)
def model(dbt, session):
return my_sql_model_df
# Database reference
my_sql_model_df = dbt.ref("test_address__mock_data")
address = 'selayang mall'
url = 'https://nominatim.openstreetmap.org/search/' + requests.utils.quote(address) + '?format=json'
response = requests.get(url).json()
return url