LoginSignup
0
1

More than 1 year has passed since last update.

Python3: Yahoo 郵便番号検索API の使い方

Posted at

参考ページ
郵便番号検索API

get_address.py
#! /usr/bin/python
#
#	get_address.py
#
#				 	Jul/31/2022
#
# ------------------------------------------------------------------
import  sys
import  os
import  json
import  requests
from dotenv import load_dotenv
# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
dotenv_path = '.env'
load_dotenv(dotenv_path)
APPID = os.environ.get("APPID")
#
code_zip = sys.argv[1];
sys.stderr.write("code_zip = %s\n" % code_zip)

url_base="https://map.yahooapis.jp/search/zip/V1/zipCodeSearch"
url = url_base + "?query=" + code_zip + "&output=json"
#
headers = { "Content-Type": "application/json",
	"User-Agent": "Yahoo AppID: " + APPID }
#
rr=requests.get(url,headers=headers)
dict_data = json.loads(rr.text)
#
#print(dict_data)
#
print(dict_data['Feature'][0]['Property']['Address'])
#
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------
.env
APPID = 'dj0zaiZpPW9NN3F****'

実行例

$ ./get_address.py 131-8634
*** 開始 ***
code_zip = 131-8634
東京都墨田区押上1-1-2東京スカイツリーイーストタワー11F
*** 終了 ***
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1