Skip to content

Commit

Permalink
fix: 네이버 지도검색시 오류 수정
Browse files Browse the repository at this point in the history
 - web.get의 headers값에 Referer 추가
 - 위치정보값이 없을 경우 기본값으로 설정한'서울시청'좌표값 수정
  • Loading branch information
inchanS committed Sep 7, 2024
1 parent a77218d commit 6a4880f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 7 additions & 5 deletions workflow/map_search_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def get_data(word, use_ip):
lang="ko",
caller="pcweb"
)
headers = {"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15"}
headers = {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15",
"Referer": "https://map.naver.com/"}
r = web.get(url, params, headers=headers)
r.raise_for_status()
return r.json().get(map_type)
Expand Down Expand Up @@ -86,8 +88,8 @@ def wrapper():
res_cache_name_ip = ''

res_json = wf.cached_data(f"{res_cache_name}{res_cache_name_ip}_{args}", wrapper, max_age=cache_age)
if not res_json:

if not res_json:
wf.add_item(
title=f"No search results for '{args}'",
icon='noresults.png',
Expand All @@ -98,7 +100,7 @@ def wrapper():
arg=f"https://map.naver.com/p/search/{args}",
quicklookurl=f"https://map.naver.com/p/search/{args}",
valid=True)

it = wf.add_item(title=f"Return... search naver map for '{args}'",
autocomplete=args,
arg=args,
Expand Down Expand Up @@ -158,7 +160,7 @@ def wrapper():
quicklookurl=f"https://map.naver.com/p/search/{txt}/{type}/{_id}",
icon='845B46E7-61FB-43CD-A287-FCB4C075A4A6.png',
valid=True)

wf.send_feedback()

if __name__ == '__main__':
Expand Down
9 changes: 6 additions & 3 deletions workflow/naver_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

from workflow import web, Workflow

default_latitude = os.getenv('latitude', '37.5665')
default_longitude = os.getenv('longitude', '37.5665')
# 위치 기본좌표는 서울시청
default_latitude = os.getenv('latitude', '37.5665851')
default_longitude = os.getenv('longitude', '126.9782038')
cache_age = int(os.getenv('cache_age', '30'))

def get_ip_location():
Expand All @@ -49,7 +50,9 @@ def get_data(locate, word):
lang="ko",
caller="pcweb"
)
headers = {"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15"}
headers = {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15",
"Referer": "https://map.naver.com/"}
r = web.get(url, params, headers=headers)
r.raise_for_status()
return r.json()
Expand Down

0 comments on commit 6a4880f

Please sign in to comment.