-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KAN-87] naver geo api를 활용하여 좌표 데이터 추가 (#20)
- Loading branch information
1 parent
5e0971f
commit 144a577
Showing
6 changed files
with
344 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
|
||
import pandas as pd | ||
import requests | ||
|
||
# 네이버 지오코딩 API 키 설정 | ||
client_id = os.getenv('NAVER_CLIENT_ID') | ||
client_secret = os.getenv('NAVER_CLIENT_SECRET') | ||
|
||
df = pd.read_csv('restaurants.csv') | ||
|
||
|
||
def get_coordinates(address): | ||
url = f"https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query={address}" | ||
headers = { | ||
"X-NCP-APIGW-API-KEY-ID": client_id, | ||
"X-NCP-APIGW-API-KEY": client_secret | ||
} | ||
response = requests.get(url, headers=headers) | ||
if response.status_code == 200: | ||
data = response.json() | ||
if data['addresses']: | ||
x = data['addresses'][0]['x'] | ||
y = data['addresses'][0]['y'] | ||
return x, y | ||
else: | ||
print("Error Code:", response.status_code) | ||
print(response.text) | ||
return None, None | ||
|
||
|
||
df['longitude'] = '' | ||
df['latitude'] = '' | ||
|
||
for idx, row in df.iterrows(): | ||
address = row['address'] | ||
x, y = get_coordinates(address) | ||
df.at[idx, 'longitude'] = x | ||
df.at[idx, 'latitude'] = y | ||
|
||
df.to_csv('restaurants.csv', index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,10 @@ | ||
from create_table_list import * | ||
from delete_table_list import * | ||
|
||
def create_table(cursor): | ||
|
||
# table deletion query | ||
cursor.execute(delete_table_restaurants) | ||
cursor.execute(delete_table_categories) | ||
cursor.execute(delete_table_restaurant_categories) | ||
cursor.execute(delete_table_operating_infos) | ||
cursor.execute(delete_table_menus) | ||
|
||
# table creation query | ||
cursor.execute(create_table_restaurants) | ||
cursor.execute(create_table_restaurant_likes) | ||
cursor.execute(create_table_categories) | ||
cursor.execute(create_table_restaurant_categories) | ||
cursor.execute(create_table_operating_infos) | ||
cursor.execute(create_table_menus) | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.