728x90
반응형
# -*- coding: utf-8 -*-
import requests
import json
from numpy.dual import _restore_dict
# 스타벅스 - store - 지역검색
def getSido():
url = 'https://www.starbucks.co.kr/store/getSidoList.do'
resp = requests.post(url)
#print(resp.json())
sido_json = resp.json()['list']
sido_code = list(map(lambda x: x['sido_cd'], sido_json))
sido_name = list(map(lambda x: x['sido_nm'], sido_json))
sido_dict = dict(zip(sido_code, sido_name))
# zip을 통해 key: value로 묶어주고 이때 zip타입으로 저장되기때문에 dictionary로 형변환 해줌
return sido_dict
def getGuGun(sido_code):
url = 'https://www.starbucks.co.kr/store/getGugunList.do'
resp = requests.post(url, data={'sido_cd': sido_code})
print(resp.json())
gugun_json = resp.json()['list']
gugun_code = list(map(lambda x: x['gugun_cd'], gugun_json))
gugun_name = list(map(lambda x: x['gugun_nm'], gugun_json))
gugun_dict = dict(zip(gugun_code, gugun_name))
return gugun_dict
def getStore(sido_code='', gugun_code=''):
url = 'https://www.starbucks.co.kr/store/getStore.do'
resp = requests.post(url, data={
'ins_lat': '37.56682',
'ins_lng': '126.97865',
'p_sido_cd': sido_code,
'p_gugun_cd': gugun_code,
'in_biz_cd': "",
'set_date': ""
})
store_json = resp.json()['list']
#print(store_json)
store_list = list()
count = 0
for store in store_json:
store_dict = dict()
store_dict['s_name'] = store['s_name']
store_dict['tel'] = store['tel']
store_dict['doro_address'] = store['doro_address']
store_dict['lat'] = store['lat']
store_dict['lot'] = store['lot']
store_list.append(store_dict)
count += 1
store_result = dict()
store_result['store_list'] = store_list
store_result['count'] = count
result = json.dumps(store_result, ensure_ascii=False)
return result
# 얘는 안되영 왜냐면 key: value로 2개만 들어갈수 있어영
# s_dict = dict(zip(
# list(map(lambda x:x['s_name'],store_json)),
# list(map(lambda x:x['tel'], store_json)),
# list(map(lambda x:x['doro_address'], store_json)),
# list(map(lambda x:x['lat'], store_json)),
# list(map(lambda x:x['lot'], store_json))
# ))
# return s_dict
if __name__ == '__main__':
print(getSido())
sido = input('도시 코드를 입력해주세요! \n')
if sido == '17':
print(getStore(sido_code=17, gugun_code=1701))
else:
print(getGuGun(sido))
gugun = input('구군 코드를 입력해주세요! \n')
print(getStore(gugun_code=gugun))
728x90
반응형
'Language > Python' 카테고리의 다른 글
[python]flask02_render_template (0) | 2020.10.13 |
---|---|
[python]flask01 (0) | 2020.10.13 |
[python]crawling_크롤링_인스타 (0) | 2020.10.12 |
[python]crawling_크롤링_naver02 (0) | 2020.10.12 |
[python]crawling_크롤링_naver01 (0) | 2020.10.12 |