API
API(Application Programming Interface)๋ฅผ ์ง์ญํ๋ฉด "์์ฉ ํ๋ก๊ทธ๋จ ํ๋ก๊ทธ๋๋ฐ ์ธํฐํ์ด์ค" ์ด๋ค.
API๋ฅผ ์ค๋ช ํ ๋, ์๋น๋น์ ๋ฅผ ๋ง์ด ๋ค๊ณค ํ๋ค.
์๋(ํ๋ก๊ทธ๋จ)์ด ๋ฉ๋ด(๋ช ๋ น)๋ฅผ ์ฃผ๋ฌธํ๋ฉด, ์ ์(API)์ ๋ฉ๋ด(๋ช ๋ น)์ ๋ฐ์ ์๋ฆฌ์ฌ(์์ฉ ํ๋ก๊ทธ๋จ)์๊ฒ ์ ๋ฌํ๋ค.
์๋ฆฌ์ฌ(์์ฉ ํ๋ก๊ทธ๋จ)๊ฐ ์๋ฆฌ(๋ช ๋ น์ ๊ฒฐ๊ณผ๊ฐ)๋ฅผ ์์ฑํ๋ฉด ์ ์(API)์ ์๋ฆฌ(๋ช ๋ น์ ๊ฒฐ๊ณผ๊ฐ)๋ฅผ ์๋(ํ๋ก๊ทธ๋จ)์๊ฒ ์ ๋ฌํ๋ค.
๐โ๏ธProgram -- ๐คAPI -- ๐ฅ Program
โต ์ด๋ฐ ๊ทธ๋ฆผ์ผ๋ก ์ค๋ช ํ ์ ์์ ๊ฒ ๊ฐ๋ค
OpenWeatherMap
openWeatherMap์์ ๋ ์จ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋ API๋ฅผ ๋ฌด๋ฃ๋ก ์ฌ์ฉํด ๋ณผ ์ ์๋ค.
ะกurrent weather and forecast - OpenWeatherMap
Access current weather data for any location on Earth including over 200,000 cities! The data is frequently updated based on the global and local weather models, satellites, radars and a vast network of weather stations. how to obtain APIs (subscriptions w
openweathermap.org
์ด๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด, ์ฌ์ดํธ์ ์ ์ํด ํ์๊ฐ์ ํ API Key๋ฅผ ๋ฐ๊ธ ๋ฐ์์ผ ํ๋ค.
API Key๋ ํด๋น API์ ์ฌ์ฉ์๋ฅผ ๊ตฌ๋ถํ๋ ์ญํ ์ ํ๋ค.
์ด API๋ ๊ฒฐ๊ณผ๊ฐ์ผ๋ก json ํ์์ ์ฌ์ฉํ๋ค.
json
javascript object notation์ ์ฝ์๋ก, ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ๋ฒ ์ค์์ ๊ฐ์ฒด(object)๋ผ๋ ๋ฌธ๋ฒ์ ๋ฐ๋ฅด๋ ๋ฌธ์๊ธฐ๋ฐ์ ๋ฐ์ดํฐ ํฌ๋งท์ด๋ค.
json์ ๋ฐ์ดํฐ๋ฅผ ์ฃผ๊ณ ๋ฐ์๋ ์ฃผ๋ก ์ฌ์ฉํ๋ ํฌ๋งท์ด๋ค! ๋ชจ์์ด Dictionary๋ ๋น์ทํ๋ฐ type์ ์ดํด๋ณด๋ฉด <str>์ด๋ค.
๋ฐ๋ผ์ ํ์ด์ฌ์์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ json ๋ชจ๋์ ํ์ฉํด์ผ ํ๋ค.
โก๏ธ json.loads(<str>) ์ ํตํด <str>์ <dict>๋ก ๋ณ๊ฒฝํ ์ ์๋ค.
Googletrans
Googletrans๋ ๊ตฌ๊ธ ๋ฒ์ญ API(Google Translate API)๋ฅผ ๊ตฌํํ ๋ฌด๋ฃ ๋ฌด์ ํ ํ์ด์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค.
https://py-googletrans.readthedocs.io/en/latest/
Googletrans: Free and Unlimited Google translate API for Python — Googletrans 3.0.0 documentation
Googletrans: Free and Unlimited Google translate API for Python Googletrans is a free and unlimited python library that implemented Google Translate API. This uses the Google Translate Ajax API to make calls to such methods as detect and translate. Feature
py-googletrans.readthedocs.io
pip install googletrans
ํด๋น ์ฝ๋๋ฅผ ํตํด ์ค์น ํ ์ฌ์ฉ ํ ์ ์๋ค. ((๊ณต์๋ฌธ์ ์ฌ์ดํธ ํ์ฉ))
.detect() : ์ธ์ด๋ฅผ ๊ฐ์งํ๋ค
.translate() : ๋ฒ์ญํ๋ค
IMAP
IMAP(Internet Messaging Access Protocol)๋ "์๋ฒ์์ ๋ฉ์ผ๋ก ์ ๊ทผํ ์ ์๋ ํ๋กํ ์ฝ"์ด๋ค.
IMAP์ ์ฌ์ฉํ๋ฉด ๋ฉ์์ง๊ฐ ์๊ฒฉ ์๋ฒ์ ์ ์ฅ๋ผ ์ด๋์๋ ๋ชจ๋ ์ฅ์น์์ ๋ฉ์์ง๋ฅผ ํ์ธํ ์ ์๋ค.
SMTP
SMTP(Simple Mail Transfer Protocol)๋ "๊ฐ๋จํ๊ฒ ๋ฉ์ผ์ ๋ณด๋ด๊ธฐ ์ํ ์ฝ์"์ด๋ค.
์ฆ, SMTP์๋ฒ๋ฅผ ์ด์ฉํด ์ฐ๋ฆฌ๊ฐ ์ํ๋ ๊ณณ์ผ๋ก ๋ฉ์ผ์ ๋ณด๋ผ ์ ์๋ค.
๐โ๏ธ Email client A - - SMTP - - > Email Server A ๐ฅ - - SMTP - - > ๐ป Email Server B - - IMAP - - > Email client B๐โ๏ธ
MIME
MIME(Multipurpose Internet Mail Extensions)๋ ์ด๋ฉ์ผ์ ์ฒจ๋ถํ ํ์ผ(์ด๋ฏธ์ง๋ ์ค๋์ค, ๋น๋์ค ๋ฑ)์ ํ ์คํธ ๋ฌธ์๋ก ๋ณํํด์ค๋ค.
ํ์ด์ฌ์์ emil.message ๋ชจ๋์์ .EmailMessage ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋ฉด ๋๋๋ฐ ์ด๊ฑฐ๋ ๋ด์ฅํจ์๋ค!
ํ์ผ ๋ชจ๋(binary)
- rb : read binary
- wb : write binary
- ab : append binary
binary๋ ์ปดํจํฐ๊ฐ ์ดํดํ๊ธฐ ๊ฐ์ฅ ์ฌ์ด ๋ฌธ์๋ก ์๊ฐํ๋ฉด ๋๋ค. jpg ๊ฐ์ ์ด๋ฏธ์ง ํ์ผ์ด๋ mp4 ๊ฐ์ ์์ ํ์ผ ๋ฑ์ ์ปดํจํฐ์์ ์ฌ์ฉํ ์ ์๊ฒ ํด์ค๋ค.
์ ๊ทํํ์
^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$
^ : ์์
$ : ๋
[a-zA-Z0-9.+_-] : a๋ถํฐ z๊น์ง, A๋ถํฐ Z๊น์ง, 0๋ถํฐ 9๊น์ง, . , + , _ , - ๊ฐ 1ํ ์ด์ ๋ฐ๋ณต๋๋ค.
\. : ์ผ๋ฐ ๋ฌธ์ . ์ ๋ํ๋ด๋ ๊ฒ
[a-zA-Z]{2,3} : a๋ถํฐ z๊น์ง, A๋ถํฐ Z๊น์ง๊ฐ ์ต์ 2ํ, ์ต๋ 3๋ฒ ๋ฐ๋ณต๋๋ค
โ ๏ธ ํด๋น ๊ธ์ ๋ฉ์์ด์ฌ์์ฒ๋ผ AI SCHOOL ๊ต์ก ๋ด์ฉ์ ๋ณต์ตํ๊ธฐ ์ํด ์์ฑํ์์ต๋๋ค
'TIL๐ฅ > ๋ฉ์์ด์ฌ์์ฒ๋ผ_AI School 5๊ธฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฉ์ฌ] AI SCHOOL 5๊ธฐ_ Day 6 (0) | 2022.03.19 |
---|---|
[๋ฉ์ฌ] AI SCHOOL 5๊ธฐ_ Day 5 (0) | 2022.03.18 |
[๋ฉ์ฌ] AI SCHOOL 5๊ธฐ_ Day 4 (0) | 2022.03.17 |
[๋ฉ์ฌ] AI SCHCOOL 5๊ธฐ_ Day2 (0) | 2022.03.15 |
[๋ฉ์ฌ] AI SCHOOL 5๊ธฐ_ Day 1 (0) | 2022.03.14 |
๋๊ธ