import pandas as pd import requests class Naver_Map(): def __init__(self): self.Client_ID = '' self.Client_Secret = '' self.api_base_url = f'https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?' self.headers = { 'X-NCP-APIGW-API-KEY-ID' : self.Client_ID, 'X-NCP-APIGW-API-KEY' : self.Client_Secret } def geocoding(self, addr): api_url = self.api_base_url + f"query={addr}" r = requests.get(api_url, headers=self.headers) if r.status_code == 200: http_normal = True else: http_normal = False if http_normal and r.json()['status'] != 'INVALID_REQUEST' and r.json()['meta']['count']!=0: data = r.json() lat = data['addresses'][0]['y'] long = data['addresses'][0]['x'] coord = [lat, long, data] return coord else: print(r.json()) if http_normal: print(r.json()['status']) return False def extract(lst, i): return [item[i] for item in lst] if __name__ == "__main__" : import argparse args = argparse.ArgumentParser() args.add_argument("--address", type=str, help="위경도를 조회할 지번/도로명 주소") args = args.parse_args() addr = args.address naver_geocode = Naver_Map() result = naver_geocode.geocoding(addr) print(result)