Skip to content

Commit

Permalink
Merge pull request #25 from inchanS/main
Browse files Browse the repository at this point in the history
Naver Map 검색 API 변경에 따른 기능 개선
  • Loading branch information
Kuniz committed Mar 20, 2024
2 parents b61ad9a + 091ed86 commit 08e5e14
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions workflow/naver_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@
"""

import sys

from workflow import web, Workflow

def get_ip_location():
r = web.get('https://map.naver.com/p/api/location')
r.raise_for_status()
data = r.json()
return data["lngLat"]

def get_data(word):
url = 'https://map.naver.com/v5/api/search'
locate = wf.cached_data('location_data', get_ip_location, max_age=30)

url = 'https://map.naver.com/p/api/search/instant-search'
params = dict(query=word,
type="all",
displayCount="10",
coords= f"{locate['lat']},{locate['lng']}",
lang="ko",
caller="pcweb"
)
Expand All @@ -38,76 +45,69 @@ def get_data(word):
r.raise_for_status()
return r.json()


def main(wf):
args = wf.args[0]

wf.add_item(title=f"Search Naver Map for '{args}'",
autocomplete=args,
arg=f"https://map.naver.com/v5/search/{args}",
quicklookurl=f"https://map.naver.com/v5/search/{args}",
arg=f"https://map.naver.com/p/search/{args}",
quicklookurl=f"https://map.naver.com/p/search/{args}",
valid=True)

def wrapper():
return get_data(args)

res_json = wf.cached_data(f"navmap_{args}", wrapper, max_age=30)
res_type = res_json["result"]["type"] # address, place, bus

if res_type == "address":
if res_json["result"][res_type]["subType"] == "jibun-address":
res_list = res_json["result"][res_type]["jibunsAddress"]["list"]
else:
res_list = res_json["result"][res_type]["roadAddress"]["list"]
address_key = "koreanAddress"
for ltxt in res_list:
if len(ltxt) > 0:
txt = ltxt[address_key].strip()
address = ltxt["name"]
wf.add_item(
title=f"Search Naver Map for \'{txt}\'",
subtitle=address,
autocomplete=txt,
arg=f"https://map.naver.com/v5/search/{txt}/{res_type}",
copytext=txt,
largetext=txt,
quicklookurl=f"https://map.naver.com/v5/search/{txt}/{res_type}",
valid=True)
elif res_type == "place":
res_list = res_json["result"][res_type]["list"]
address_key = "roadAddress"
for ltxt in res_list:
if len(ltxt) > 0:
txt = ltxt["name"]
address = ltxt[address_key]
_id = ltxt["id"]
wf.add_item(
title=f"Search Naver Map for \'{txt}\'",
subtitle=address,
autocomplete=txt,
arg=f"https://map.naver.com/v5/search/{txt}/{res_type}/{_id}",
copytext=txt,
largetext=txt,
quicklookurl=f"https://map.naver.com/v5/search/{txt}/{res_type}/{_id}",
valid=True)
elif res_type == "bus":
res_list = res_json["result"][res_type]["busRoute"]["list"]
res_type = "bus-route"
address_key = "cityName"
for ltxt in res_list:
if len(ltxt) > 0:
txt = ltxt["name"]
address = ltxt[address_key] + "버스 " + txt
_id = ltxt["id"]
wf.add_item(
title=f"Search Naver Map for \'{txt}\'",
subtitle=address,
autocomplete=txt,
arg=f"https://map.naver.com/v5/search/{txt}/{res_type}/{_id}",
copytext=txt,
largetext=txt,
quicklookurl=f"https://map.naver.com/v5/search/{txt}/{res_type}/{_id}",
valid=True)
if len(res_json["address"]) > 0:
for ltxt in res_json["address"]:
address_key = "fullAddress"
txt = ltxt[address_key]
address = ltxt["title"]
type = ltxt["fullAddress"]
wf.add_item(
title=f"Search Naver Map for \'{txt}\'",
subtitle=address,
autocomplete=txt,
arg=f"https://map.naver.com/p/search/{txt}/{type}",
copytext=txt,
largetext=txt,
quicklookurl=f"https://map.naver.com/p/search/{txt}/{type}",
valid=True)
elif len(res_json["place"]) > 0:
for ltxt in res_json["place"]:
address_key = "roadAddress"
txt = ltxt["title"]
if not ltxt.get(address_key):
address_key = "jibunAddress"
address = ltxt[address_key]
_id = ltxt["id"]
type = ltxt["type"]
wf.add_item(
title=f"Search Naver Map for \'{txt}\'",
subtitle=address,
autocomplete=txt,
arg=f"https://map.naver.com/p/search/{txt}/{type}/{_id}",
copytext=txt,
largetext=txt,
quicklookurl=f"https://map.naver.com/p/search/{txt}/{type}/{_id}",
valid=True)
elif len(res_json["bus"]) > 0:
for ltxt in res_json["bus"]:
type = "bus-route"
address_key = ltxt["cityName"]
txt = ltxt["title"]
address = address_key + "버스 " + txt
_id = ltxt["id"]
wf.add_item(
title=f"Search Naver Map for \'{txt}\'",
subtitle=address,
autocomplete=txt,
arg=f"https://map.naver.com/p/search/{txt}/{type}/{_id}",
copytext=txt,
largetext=txt,
quicklookurl=f"https://map.naver.com/p/search/{txt}/{type}/{_id}",
valid=True)

wf.send_feedback()

Expand Down

0 comments on commit 08e5e14

Please sign in to comment.