์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array ๊ฐ์ฒด
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey๐ณ๐
[49] 230309 Ch. 6 Flask๋ฅผ ํ์ฉํ ์ผ์ ์ ์ด: 8. ๊ณต๊ณต๋ฐ์ดํฐ ํ์ฉํ๊ธฐ [K-๋์งํธ ํธ๋ ์ด๋ 49์ผ] ๋ณธ๋ฌธ
[49] 230309 Ch. 6 Flask๋ฅผ ํ์ฉํ ์ผ์ ์ ์ด: 8. ๊ณต๊ณต๋ฐ์ดํฐ ํ์ฉํ๊ธฐ [K-๋์งํธ ํธ๋ ์ด๋ 49์ผ]
yjyuwisely 2023. 3. 9. 09:17230309 Thu 49th class
Ch. 6 Flask๋ฅผ ํ์ฉํ ์ผ์ ์ ์ด
์ง๋: p. 212 ~ (๊ต์ฌ: IoT ์ฌ๋ฌผ์ธํฐ๋ท์ ์ํ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด 4 ์ ์, ์ ์: ์ต์ฃผํธ , ๊น์ฌ๋ฒ , ์ ๋์ง)
๊ต์ฌ ์ฝ๋ ๊นํ๋ธ: https://github.com/codingspecialist/RaspberryPi4-Book-Example
๊ต์ฌ ์์ค ๋ฐ PPT: http://jspstudy.co.kr/main/main.jsp
์ ์ ์นดํ: https://cafe.naver.com/metacoding
์ค๋ ๋ฐฐ์ด ๊ฒ ์ค ๊ธฐ์ตํ ๊ฒ์ ์ ๋ฆฌํ๋ค.
๋ฐฐ์ ๋ ๊ฒ ์ค ๋ค์ ๊ธฐ์ตํ๊ธฐ
2023.02.23 - [๐ณK-Digital Revision 2023โจ/Raspberry Pi, Linux, Python] - [K-๋์งํธ ํธ๋ ์ด๋ 40์ผ] 230223 Ch. 3 ๋ผ์ฆ๋ฒ ๋ฆฌ ํ์ด๋ฅผ ์ํ ํ์ด์ฌ ๊ธฐ์ด ๋ฐฐ์ฐ๊ธฐ: 1. ํ์ด์ฌ ์์ํ๊ธฐ, 2. ํ์ด์ฌ ์๋ฃํ
ํ์ด์ฌ
1. ๋ฆฌ์คํธ ์๋ฃํ: [,] ๋๊ดํธ๋ฅผ ์ด๊ณ ๋ซ๋๋ค. ๋ฐฐ์ด๊ณผ ํก์ฌํ ๊ฐ๋
์ด๋ค.
[0,0,0,0]
[1, 2, 3]
li = [10,"์ฅ๋๊ฑด",23,"์์ธ]
li | 10 | ์ฅ๋๊ฑด | 23 | ์์ธ |
li[0] | li[1] | li[2] | li[3] |
2. ํํ ์๋ฃํ: (,) ์๊ดํธ๋ก ์ด๊ณ ๋ซ๋๋ค. ๊ดํธ(,)๋ ์๋ต ๊ฐ๋ฅํ๋ค.
ํํ์ ํ ๋ฒ ๊ฐ์ ์ ํ๋ฉด ๋ด๋ถ์ ๊ฐ์ ๋ฐ๊ฟ ์๊ฐ ์๋ค.
์ฝ๊ธฐ ์ ์ฉ์ด๋ค.
('red', 4, 'python', True)
(1, 2, 3)
tu = (10, "์ฅ๋๊ฑด", 23, "์์ธ")
tu | 10 | ์ฅ๋๊ฑด | 23 | ์์ธ |
tu[0] | tu[1] | tu[2] | tu[3] |
3. ๋์
๋๋ฆฌ ์๋ฃํ: {,} ์ค๊ดํธ๋ก ์ด๊ณ ๋ซ๋๋ค.
{dict = ["๋ฒํธ":10, "์ฑ๋ช
": "์ฅ๋๊ฑด", "๋์ด":23, "์ฌ๋๊ณณ":"์์ธ"}
dict["์ฌ๋๊ณณ"] = "๊ฒฝ๊ธฐ๋"
dic (value) | 10 | ์ฅ๋๊ฑด | 23 | ์์ธ |
(key) | dic[๋ฒํธ] | dic[์ฑ๋ช ] | dic[๋์ด] | dic[์ฌ๋๊ณณ] |
Ch. 6 Flask๋ฅผ ํ์ฉํ ์ผ์ ์ ์ด
์ฑ ์ ๋ชฉ์ฐจ
01 _ Flask ์ธํ ํ๊ธฐ
01-1 ๋ผ์ฆ๋ฒ ๋ฆฌ 4์์ ์ค์นํ๊ธฐ
01-2 Flask ์ค์นํ๊ธฐ
02 _ Flask ์น์๋ฒ ๊ตฌ์ถํ๊ธฐ
03 _ Flask ๋ผ์ฐํ
04 _ Flask LED ์ ์ดํ๊ธฐ
04-1 Flask LED ์ ์ด ์ ์ ๋ผ์ฐํ
04-2 Flask LED ์ ์ด ๋์ ๋ผ์ฐํ ใ์ฐํ๊ดํธใ
04-3 Flask LED ์ ์ด ๋์ ๋ผ์ฐํ ใ์ฟผ๋ฆฌ์คํธ๋งใ
05 _ Flask ์นํ์ด์ง
05-1 Flask, HTML, CSS, Javascript๋ฅผ ์ด์ฉํ ์นํ์ด์ง ๋ง๋ค๊ธฐ
05-2 fetch() ํจ์ ์ดํดํ๊ธฐ
05-3 ํ์ดํ ํจ์ ์ดํดํ๊ธฐ
06 _ IP, Port, Process ๊ฐ๋ ์ก๊ธฐ
06-1 IP ๊ฐ๋ ์ก๊ธฐ
06-2 Port ๊ฐ๋ ์ก๊ธฐ
06-3 Process ๊ฐ๋ ์ก๊ธฐ
07 _ cron๊ณผ daemon ๊ฐ๋ ์ก๊ธฐ
07-1 cron(ํฌ๋ก ) ๊ฐ๋ ์ก๊ธฐ
07-2 daemon(๋ฐ๋ชฌ) ๊ฐ๋ ์ก๊ธฐ
08 _ ๊ณต๊ณต๋ฐ์ดํฐ ํ์ฉํ๊ธฐ
08-1 ๊ณต๊ณต๋ฐ์ดํฐ ์ ์ฒญํ๊ธฐ
08-2 ๊ณต๊ณต๋ฐ์ดํฐ ๋ถ์ํ๊ธฐ
08-3 ํ์ด์ฌ์ ํ์ฉํ์ฌ ์จ์ต๋ ํ์ธํ๊ธฐ
ํ์ต๋ชฉํ
ํ์ต๋ด์ฉ
8 ๊ณต๊ณต๋ฐ์ดํฐ ํ์ฉํ๊ธฐ
8.1 ๊ณต๊ณต๋ฐ์ดํฐ ์ ์ฒญํ๊ธฐ
์ ์ ์ธ ๋ฐ์ดํฐ: ๊ณ ์ ๋ ๋ฐ์ดํฐ, ํ์ผ๋ฐ์ดํฐ ์ด์ฉํ๋ค. ex) ์งํ์ฒ ๋
ธ์ ๋
๋์ ์ธ ๋ฐ์ดํฐ: ์์๊ฐ๊ฐ ๋ฌ๋ผ์ง๋ค. ์คํ API ์ฌ์ฉํ๋ค. ex) ๋ ์จ
์ธ์ฆํค๋ฅผ ์๋ฐ์คํฌ๋ฆฝํธ์ ๋ฃ๋๋ค. ์ธ์ฆ = ๊ตฌ๊ธ์ด ํ๋ฝํจ
์ฐธ๊ณ : https://www.educba.com/encoding-vs-decoding/
์ฐธ๊ณ ๋ฌธ์์ ์ฒจ๋ถํ์ผ์ ๋ค์ด ๋ฐ์ผ๋ฉด ์คํ API ํ์ฉ ๊ฐ์ด๋ 2๊ฐ๋ฅผ ๋ค์ด๋ก๋ํ ์ ์๋ค.
XML
<๋ณ์๋ช >๊ฐ</๋ณ์๋ช >
<baseDate>20230309</baseDate>
json (์๋ฐ์คํฌ๋ฆฝํธ์์ ์ฃผ๋ก ์ด๋ค.)
{๋ณ์๋ช : ๊ฐ}
{baseDate:20230309}
ํ๊ทธ ํ์์ผ๋ก ๋ฌถ์ ๊ฒ: xml ํ์
"๋ณ์":"๋ฃ์ ๊ฐ"
๋ง์ง๋ง ์ฝ๋: ํ๋๋ก ๋ฌถ์ ๊ฒ {}
https://www.data.go.kr/iim/api/selectDevAcountList.do
15. ์์ธ ์ค๋ช
๋ฒํผ์ ํด๋ฆญํ ๋ค ๊ธฐ์ ๋ฌธ์๋ฅผ ๋ค์ด๋ก๋ ํ ์ ์๋ค.
https://www.data.go.kr/iim/api/selectAPIAcountView.do
https://www.data.go.kr/tcs/dss/selectApiDataDetailView.do?publicDataPk=15084084
์๋ ์ฝ๋๋ ์ถ๊ฐํ๋ค.
from urllib.parse import unquote
# Python3 ์ํ ์ฝ๋ #
import requests
from urllib.parse import unquote
url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getUltraSrtNcst'
#params ={'serviceKey' : '์๋น์คํค', 'pageNo' : '1', 'numOfRows' : '1000', 'dataType' : 'XML', 'base_date' : '20210628', 'base_time' : '0600', 'nx' : '55', 'ny' : '127' }
params ={'serviceKey' : 'EYhwxJp0FE8gd5Ov8DFbBlqYKBx3ApWbtwH82mV72t7zag3R1sChGhzfXH3ohLVrrbbnpHMq4iQ9g0ogvImPIw%3D%3D', 'pageNo' : '1', 'numOfRows' : '1000', 'dataType' : 'XML', 'base_date' : '20210628', 'base_time' : '0600', 'nx' : '55', 'ny' : '127' }
response = requests.get(url, params=params)
print(response.content)
#ํฐ๋ฏธ๋
pi@rasberrypi: webapps/ch06/weather $ cd /home/pi/webapps/ch06/weather
pi@rasberrypi: webapps/ch06/weather $ python weather_test.py
#๊ฒฐ๊ณผ ๋์ด
8.2 ๊ณต๊ณต๋ฐ์ดํฐ ๋ถ์ํ๊ธฐ
8.3 ํ์ด์ฌ์ ํ์ฉํ์ฌ ์จ์ต๋ ํ์ธํ๊ธฐ
https://www.data.go.kr/tcs/dss/selectApiDataDetailView.do?publicDataPk=15084084
'์๋น์คํค'์ ์ผ๋ฐ ์ธ์ฆํค๋ฅผ ๋ฃ๋๋ค.
EYhwxJp0FE8gd5Ov8DFbBlqYKBx3ApWbtwH82mV72t7zag3R1sChGhzfXH3ohLVrrbbnpHMq4iQ9g0ogvImPIw%3D%3D
|
์ต์ข ์ฝ๋ p. 223
from urllib.parse import urlencode, unquote
import requests
import json
url = "http://newsky2.kma.go.kr/service/SecndSrtpdFrcstInfoService2/ForecastGrib"
queryString = "?" + urlencode(
{
"ServiceKey" : unquote("wJmmW29e3AEUjwLioQR22CpmqS645ep4S8TSlqtSbEsxvnkZFoNe7YG1weEWQHYZ229eNLidnI2Yt5EZ3Stv7g%3D%3D"),
"base_date" : "20190407",
"base_time" : "1200",
"nx" : "59", #๊ธฐ์์ฒญ ๊ฒฉ์ ์ ๋ณด
"ny" : "127", #๊ธฐ์์ฒญ ๊ฒฉ์ ์ ๋ณด
"numOfRows" : "10",
"pageNo" : "1",
"_type" : "json"
}
)
response = requests.get(url + queryString)
print("===== response json data start =====")
print(response)
print("===== response json data end =====")
print()
r_dict = json.loads(response.text)
r_response = r_dict.get("response")
r_body = r_response.get("body")
r_items = r_body.get("items")
r_item = r_items.get("item")
result = {} #์ต์ข
๊ฒฐ๊ณผ๋ ๋์
๋๋ฆฌ ํํ
for item in r_item:
if(item.get("category") == "T1H"): #์๋ฃ ๊ตฌ๋ถ ์ฝ๋ ๊ฐ: ๊ธฐ์จ p.213 ์ฐธ๊ณ
result = item
break
print("===== response dictionary(python object) data start =====")
print(result)
print("===== response dictionary(python object) end =====")
print()