์ฐ๋ฆฌ ์ดํ์์ ํ์ฌ ๋ชจ์์ ๋ง๋ค ๋ ๋ฌ๋ ฅ์ ๋ ์ ์ฒดํฌํ์ฌ ๋ชจ์ ์ผ์ ์ ์์ฑํ๋ค.
ํ์ฌ๋ ๊ทธ๋ฅ ๋ฌ๋ ฅ์ ์๋ฌด๋ฐ ํ์๊ฐ ๋์ด ์์ง ์๋ค.
์ด๋ ๋ฌ๋ ฅ์ ํด๋น ๋ ์ง์ ๋ ์จ๊ฐ ์ ํ์๋ค๋ฉด ๋ ์ ์ ์ ํ๋๋ฐ ๋์์ด ๋์ง ์์๊น ์ถ์ด ์๊ฐํ๊ฒ ๋์๋ค.
๊ธฐ์์ฒญ API๋ฅผ ํ์ฉํ์ฌ ์ฅ์๋ฅผ ๊ณ ๋ฅด๋ฉด 10์ผ๊น์ง์ ๋ ์จ๋ฅผ ์ ์ ์๋ ์ค๊ธฐ์ก์์๋ณด API๋ฅผ ํ์ฉํ์ฌ ๋ํ๋ธ๋ค.
์ฌ๊ธฐ๊น์ง์ ์์ด๋์ด๋ ์๋ ๊ฒ์๊ธ์ ์ฐธ๊ณ ํ๋ฉด ๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋ชจ์๋ ์ง๊ฐ ๋๋ฉด ๋ชจ์์ด ์์๋๊ธฐ 6์๊ฐ ์ ์ ๋ฏธ๋ฆฌ ์๋ฆผ์ผ๋ก ํด๋น ๋ชจ์์ธ์๋ค์๊ฒ ์๋ฆผ์ ๋ณด๋ด์ฃผ๋ ๊ฒ์ด๋ค.
์๋ ์ฌ์ง์ ์์ง ๋์ ๋์ง ์์์ ๋ด๊ฐ ์์๋ก ๋ง๋ค์๋ค.
๋จผ์ ๋ฐ์ดํฐํฌํธ์ ๋ค์ด๊ฐ์ APIํค๋ฅผ ๋ฐ๋๋ค. ํค๋ฅผ ๋ฐ๋ ๋ฐฉ๋ฒ์ ์์ ์ฌ๋ ค๋ ๊ฒ์๊ธ์์ ํ์ธ ๊ฐ๋ฅํ๋ค.
๋จ๊ธฐ์๋ณด ์กฐํ์๋น์ค๋ Decoding key๊ฐ ์ ์ฉ๋๋ ๋ฏ ํ๋ค. ์ผ๋ฐ ์ธ์ฆํค๋ฅผ ๋ณต์ฌํด์ ์ ์ด๋๋๋ค.
!pip install requests
!pip install beautifulsoup4
!pip install json
def weather(target):
def now_weather_info():
url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getUltraSrtNcst'
params = {
'serviceKey' : '์๊น ์ ์ด๋์ ๋ณธ์ธ์ ํค๊ฐ',
'pageNo' : '1',
'numOfRows' : '1000',
'dataType' : 'JSON',
'base_date' : '20230220',
'base_time' : '1500',
'nx' : '58',
'ny' : '75'
}
r = requests.get(url, params=params)
response = json.loads(r.content)
print(response)
def today_gathering():
url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getUltraSrtFcst'
params = {
'serviceKey' : '์๊น ์ ์ด๋์ ๋ณธ์ธ์ ํค๊ฐ',
'pageNo' : '1',
'numOfRows' : '1000',
'dataType' : 'JSON',
'base_date' : '20230220',
'base_time' : '0900',
'nx' : '58',
'ny' : '75'
}
r = requests.get(url, params=params)
response = json.loads(r.content)
print(response)
_function = {'now_weather_info': now_weather_info, 'today_gathering': today_gathering}
_function[target]()
# gwangju('festival')
weather('today_gathering')
๋ ์จ api๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ๊ธฐ ๋๋ฌธ์ ํจ์๋ก ๊ธฐ๋ฅ๋ค์ ๋ฌถ์ด์ฃผ์๋ค.
๋ด๊ฐ ์ฌ์ฉ์ ํ์ง ์์ ๊ฑฐ์ง๋ง ์ฐ์ ํ์ธํด๋ณด๋ ค๊ณ ํจ์๋ฅผ ๋ง๋ค์๋ค.
now_weather_info()๋ ์์ธก์ ๋ณด๋ผ๊ธฐ๋ณด๋ค๋ ํ์ฌ์ ์ ๋ณด๋ค์ ๋ณด์ฌ์ค๋ค.
2023๋ 02์ 20์ผ์ ๋ ์จ ์ค, ํ์ฌ ์๊ฐ์ด 16์๋ผ๋ฉด base_date๋ 20230220, base_time์ 1500์ ์ ์ด์ค๋ค.
nx, ny๋ ์๋์์ ํ๊บผ๋ฒ์ ์๋ ค์ฃผ๋ ค๊ณ ํ๋ค.
params = {
'serviceKey' : '์๊น ์ ์ด๋์ ๋ณธ์ธ์ ํค๊ฐ',
'pageNo' : '1',
'numOfRows' : '1000',
'dataType' : 'JSON',
'base_date' : '20230220',
'base_time' : '0900',
'nx' : '58',
'ny' : '75'
}
today_gathering()ํจ์ ๋ด api ํธ์ถ ํ๋ผ๋ฏธํฐ์ ๋ํด ์๋ ค์ฃผ๋ คํ๋ค.
๋จผ์ ํจ์๋ ์์ ๋กญ๊ฒ ์ด๋ฆ์ ์ง์ผ๋ฉด ๋๋๋ฐ
๋๋ ์ดํ์ ์ค๋ ๋ชจ์ ์๋ฆผ์ด๋ฏ๋ก ํจ์์ด๋ฆ์ today_gathering์ผ๋ก ์ง์๋ค.
url์ ํธ์ถ์ฃผ์์ด๊ณ , params๋ ์ด๋ค ์ ๋ณด๋ฅผ ์๊ตฌํ ์ง ์ ๋ ๊ณณ์ด๋ค.
'serviceKey'๋ ๋ณธ์ธ์ ํค๊ฐ์ ์ ์ผ๋ฉด ๋๋ค. ์ธ์ฝ๋ฉ, ๋์ฝ๋ฉ ํค๋ฅผ ๋๋ค ๋ฃ์ด๋ณด๊ณ ๋๋ ๊ฐ์ ์ ์ผ๋ฉด ๋๋ค.
'pageNo' , 'numOfRows'๋ ์ ๋ชจ๋ฅด๊ฒ ๋ค. ๊ฐ์ ๋ฐ๊ฟ๋ด๋ ๊ฐ์ ๊ฐ์ด ๋์จ๋ค.
'dataType'์ ๋ฆฌํด๊ฐ์ 'JSON'ํ์์ผ๋ก ๋ฐ์์ง 'XML'ํ์์ผ๋ก ๋ฐ์์ง ์ ํ์ด ๊ฐ๋ฅํ๋ค.
'base_date'๋ ๋ ์ง๋ฅผ ์ ์ผ๋ฉด ๋๋๋ฐ ์ต๊ทผ 3์ผ๊ฐ์ ์๋ฃ๋ง ์ ๊ณต๊ฐ๋ฅํ๋ค.
{'response': {'header': {'resultCode': '10', 'resultMsg': '์ต๊ทผ 3์ผ ๊ฐ์ ์๋ฃ๋ง ์ ๊ณตํฉ๋๋ค.'}}}
{'response': {'header': {'resultCode': '03', 'resultMsg': 'NO_DATA'}}}
๋๋ฌด ์์ ์ ๋ ์ง๋ ๋ฏธ๋์ ์๊ฐ์ด๋ ๋ ์ง๋ฅผ ์ ์ผ๋ฉด ์์ ์๋ต์ ๋ฐ๊ฒ ๋๋ค.
'base_time'์ ํ์ฌ ์๊ฐ๋ณด๋ค ์ฝ 30๋ถ์์ 1์๊ฐ์ ๋ ์ ์ ์๊ฐ์ ์ ๋๊ฒ ์ข๋ค.
'rx', 'ry'๋ ๊ทธ ์ง์ญ์ x๊ฐ, y๊ฐ์ ์ ์ด์ฃผ๋ฉด ๋๋ค.
ํ์ผ์ ๋ค์ด๋ก๋ ๋ฐ์ผ๋ฉด ๋ณธ์ธ์ด ํ์ธํ๊ณ ์ถ์ ์ง์ญ์ ์ฐพ์์ ๊ฒฉ์x, ๊ฒฉ์y๊ฐ์ ์ ๋ ฅํด์ฃผ๋ฉด ๋๋ค.
์๋๋ ๊ณต์๋ฌธ์์ ํ์ด๋ ์ฐธ๊ณ ํ๋ฉด ๋๋ค.
{'response': {'header': {'resultCode': '00', 'resultMsg': 'NORMAL_SERVICE'}, 'body': {'dataType': 'JSON', 'items': {'item': [{'baseDate': '20230220', 'baseTime': '0930', 'category': 'LGT', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'LGT', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'LGT', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'LGT', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'LGT', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'LGT', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'PTY', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'PTY', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'PTY', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'PTY', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'PTY', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'PTY', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '0', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'RN1', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '๊ฐ์์์', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'RN1', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '๊ฐ์์์', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'RN1', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '๊ฐ์์์', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'RN1', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '๊ฐ์์์', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'RN1', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '๊ฐ์์์', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'RN1', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '๊ฐ์์์', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'SKY', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'SKY', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'SKY', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'SKY', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'SKY', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'SKY', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'T1H', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '3', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'T1H', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '4', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'T1H', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '5', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'T1H', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '6', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'T1H', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '6', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'T1H', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '5', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'REH', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '65', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'REH', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '55', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'REH', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '50', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'REH', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '40', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'REH', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '40', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'REH', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '40', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'UUU', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '0.5', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'UUU', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '1.4', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'UUU', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '2.4', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'UUU', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '2.9', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'UUU', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '3.1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'UUU', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '3.4', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VVV', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '0.6', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VVV', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '0.2', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VVV', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '-1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VVV', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '-3.5', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VVV', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '-4.8', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VVV', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '-5.1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VEC', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '219', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VEC', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '263', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VEC', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '293', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VEC', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '321', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VEC', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '328', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'VEC', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '327', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'WSD', 'fcstDate': '20230220', 'fcstTime': '1000', 'fcstValue': '1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'WSD', 'fcstDate': '20230220', 'fcstTime': '1100', 'fcstValue': '1', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'WSD', 'fcstDate': '20230220', 'fcstTime': '1200', 'fcstValue': '3', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'WSD', 'fcstDate': '20230220', 'fcstTime': '1300', 'fcstValue': '5', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'WSD', 'fcstDate': '20230220', 'fcstTime': '1400', 'fcstValue': '6', 'nx': 58, 'ny': 75}, {'baseDate': '20230220', 'baseTime': '0930', 'category': 'WSD', 'fcstDate': '20230220', 'fcstTime': '1500', 'fcstValue': '6', 'nx': 58, 'ny': 75}]}, 'pageNo': 1, 'numOfRows': 1000, 'totalCount': 60}}} |
์ ๋๋ก ์ ๋ ฅํ์ฌ ์คํ์ํค๋ฉด ์์ ๊ฐ์ ํธ์ถ๊ฐ์ ๋ฐ๊ฒ ๋๋๋ฐ ์ ์ ์๋ค.
๋๋ ์ฒ์์ ์ด ๋ฐ์ดํฐ๋ฅผ ๋ฐ๊ณ ๋ฌผ์ํ๊ฐ ๋์๋ค.
๋จผ์ ํ๋์ฉ ํ๋ฉด ๋ด๊ฐ ์ ์ ์๊ฐ(base_time) ์ดํ 6์๊ฐ๊น์ง์ ์๋ณด๋ฅผ ์๋ ค์ค๋ค.
๊ทธ๋ฆฌ๊ณ XX:30์ผ๋ก ํต์ผ๋๋ ๋ฏ ํ๋ค.
base_time ์ 1000์ผ๋ก ์ ์ด๋ 1030์ผ๋ก ์ ์ก๋๋ค.
์ด ๊ฐ์ ์กฐ๊ธ ๋ณด๊ธฐ ์ข๊ฒ ๋ฐ๊ฟ๋ณด๊ฒ ๋ค.
1์๊ฐ ํ์ ๊ด์ฃผ ๋๋ฆผ๋ ์ผ๊ธฐ์๋ณด์
๋๋ค. ๋๋ขฐ : 0 ๊ฐ์ํํ : ์์ 1์๊ฐ ๊ฐ์๋ : ๊ฐ์์์ ํ๋์ํ : ๋ง์ ๊ธฐ์จ : 6 ์ต๋ : 55 ๋์๋ฐ๋์ฑ๋ถ : 1.2 ๋จ๋ถ๋ฐ๋์ฑ๋ถ : -0.1 ํํฅ : 277 ํ์ : 1 2์๊ฐ ํ์ ๊ด์ฃผ ๋๋ฆผ๋ ์ผ๊ธฐ์๋ณด์ ๋๋ค. ๋๋ขฐ : 0 ๊ฐ์ํํ : ์์ 1์๊ฐ ๊ฐ์๋ : ๊ฐ์์์ ํ๋์ํ : ๊ตฌ๋ฆ๋ง์ ๊ธฐ์จ : 7 ์ต๋ : 50 ๋์๋ฐ๋์ฑ๋ถ : 2.3 ๋จ๋ถ๋ฐ๋์ฑ๋ถ : -0.6 ํํฅ : 287 ํ์ : 2 3์๊ฐ ํ์ ๊ด์ฃผ ๋๋ฆผ๋ ์ผ๊ธฐ์๋ณด์ ๋๋ค. ๋๋ขฐ : 0 ๊ฐ์ํํ : ์์ 1์๊ฐ ๊ฐ์๋ : ๊ฐ์์์ ํ๋์ํ : ๋ง์ ๊ธฐ์จ : 7 ์ต๋ : 40 ๋์๋ฐ๋์ฑ๋ถ : 2.8 ๋จ๋ถ๋ฐ๋์ฑ๋ถ : -2.5 ํํฅ : 313 ํ์ : 4 (์ค๋ต) |
์ ํ์์ด 1,2,3,4 ... ๋ก ๊ฐ๋์ง๋ ์ฐ์ฐ์ธ์ง api๊ฐ ์๋ชป๋๊ฑด์ง ๋ชจ๋ฅด๊ฒ ๋ค.
def weather(target):
def today_gathering():
url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getUltraSrtFcst'
params = {
'serviceKey' : '๋ณธ์ธ์ ํค๊ฐ',
'pageNo' : '1',
'numOfRows' : '1000',
'dataType' : 'JSON',
'base_date' : '20230220',
'base_time' : '1000',
'nx' : '58',
'ny' : '75'
}
r = requests.get(url, params=params)
response = json.loads(r.content)
if response['response']['header']['resultCode'] != '00':
return response['response']['header']['resultMsg']
else:
code_name = {'T1H': '๊ธฐ์จ', 'RN1': '1์๊ฐ ๊ฐ์๋', 'SKY': 'ํ๋์ํ', 'UUU': '๋์๋ฐ๋์ฑ๋ถ', 'VVV': '๋จ๋ถ๋ฐ๋์ฑ๋ถ',
'REH': '์ต๋', 'PTY': '๊ฐ์ํํ', 'LGT': '๋๋ขฐ', 'VEC': 'ํํฅ', 'WSD': 'ํ์'}
sky_value = {'1': '๋ง์', '3': '๊ตฌ๋ฆ๋ง์', '4': 'ํ๋ฆผ'}
pty_value = {'0': '์์', '1': '๋น', '2': '๋น/๋', '3': '๋', '5': '๋น๋ฐฉ์ธ', '6': '๋น๋ฐฉ์ธ/๋๋ ๋ฆผ', '7': '๋๋ ๋ฆผ'}
result = {'1': {}, '2': {}, '3': {}, '4': {}, '5': {}, '6': {}}
for i, v in enumerate(response['response']['body']['items']['item']):
if v['category'] == 'SKY':
result[str(i%6 + 1)][code_name[v['category']]] = sky_value[v['fcstValue']]
elif v['category'] == 'PTY':
result[str(i%6 + 1)][code_name[v['category']]] = pty_value[v['fcstValue']]
else:
result[str(i%6 + 1)][code_name[v['category']]] = v['fcstValue']
return result
_function = {'today_gathering': today_gathering}
return _function[target]()
# gwangju('festival')
result = weather('today_gathering')
for i in result.keys():
print(i+'์๊ฐ ํ์ ๊ด์ฃผ ๋๋ฆผ๋ ์ผ๊ธฐ์๋ณด์
๋๋ค.')
for k, v in result[i].items():
print(k, ':', v)
print()
์ผ๋จ์ ์ด๋ ๊ฒ ๋ฐ๊ฟ๋ณด์๋๋ฐ ํ์, ํํฅ, ์ต๋ ๋ฑ์ ๊ธฐํธ๋ฅผ ์๋ง๊ฒ ์ถ๊ฐ๋ก ๋ฃ์ผ๋ฉด ๋ ๋ฏํ๋ค.
์๋ ํ๋ฅผ ์ฐธ๊ณ ํ์ฌ๋ ๋๋ค.
์คํ api ๊ฐ์ด๋๋ฅผ ๋ณด๊ณ ๋ง๋ค์ด๋ณด์๋ ๋๋ค.
๋ด๊ฐ ๋ง๋ ์ฝ๋๋ ์ ์์ ํ๊ธฐ ์ํด ์ ๊น ๋ง๋ ์ฝ๋๋ผ ํ์ฌ ์์ฑํ๋ค.
๋ํ๋๊ป์ ์งํํ๋ผ๊ณ ํ์๋ฉด FEํ๊ณผ ์์ํ์ฌ ์ฝ๋๋ฅผ ๋ค์ ์ง์ผ ํ๋ค.
'๐๐ฎ๐ฉ๐๐ค๐ฃ > ๐ผ๐๐' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋์ค์ฝ๋ ๋ด] ๋กค ์ ์ ๊ฒ์๊ธฐ๋ฅ ๋ง๋ค๊ธฐ - 1 (0) | 2024.03.17 |
---|---|
ํ์ด์ฌ ๊ฐ์ข OCR ์ฌ์ฉํด๋ณด๊ธฐ ๋ฐ ๋ค์ด๋ฒ ํด๋ผ์ฐ๋ AI OCR ์ฌ์ฉ๋ฒ (1) (0) | 2023.03.30 |
ํ์ด์ฌ์ผ๋ก ๊ธฐ์์ฒญ ์ผ๊ธฐ์๋ณด์ ๋ ์จ API ์ฌ์ฉํ๊ธฐ (0) | 2023.02.18 |
koGPT, openAI GPT3 ์ฌ์ฉํด๋ณด๊ธฐ (chat gpt3, dall-e) (0) | 2023.02.13 |
์นด์นด์ค API 'Karlo', stable diffusion ์ฌ์ฉํด๋ณด๊ธฐ (0) | 2023.02.12 |
๋๊ธ