๋ฌด์์ ๋๊ผ๋๊ฐ.
[์ค๋ ํ๋ฃจ ํ๊ธฐ์ ๋ฐฐ์ด ๋ด์ฉ ๊ธฐ๋กํ๊ธฐ]
ํ๋ก์ ํธ ์์ ์ ์ธํฐํ๋ฆฌํฐ ์ฌ์ ์ค์น
- flask, pymongo, dnspython
ํ๋ก์ ํธ ์๋ฒ ๊ตฌ์ถ
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route("/movie", methods=["POST"])
def movie_post():
sample_receive = request.form['sample_give']
print(sample_receive)
return jsonify({'msg':'POST ์ฐ๊ฒฐ ์๋ฃ!'})
@app.route("/movie", methods=["GET"])
def movie_get():
return jsonify({'msg':'GET ์ฐ๊ฒฐ ์๋ฃ!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
๋ฐ์ดํฐ DB ์ ์ฅ ํผ
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client.dbprac
@app.route("/")
def home():
return render_template('index.html')
@app.route("/movie", methods=["POST"])
def movie_post():
url_receive = request.form['url_give']
star_receive = request.form['star_give']
comment_receive = request.form['comment_give']
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get(url_receive, headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
image = soup.select_one('meta[property="og:image"]')['content']
title = soup.select_one('meta[property="og:title"]')['content']
desc = soup.select_one('meta[property="og:description"]')['content']
doc = {
'image': image,
'title': title,
'desc': desc,
'star': star_receive,
'comment': comment_receive
}
db.movies.insert_one(doc)
return jsonify({'msg': '์ ์ฅ ์๋ฃ!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
ํฌ์คํ
API
- ํด๋ผ์ด์ธํธ์์ ์ค ๋ฐ์ดํฐ: ์ ๋ชฉ, ์ฝ๋ฉํธ
- ์๋ฒ์์ ํ ์ผ: ์ ๋ชฉ, ์ฝ๋ฉํธ๋ฅผ DB์ ์ ์ฅ
- ์๋ฒ์์ ์ค ๊ฒ: ์ ์ ์ฅ๋๋ค๋ ๋ฉ์์ง
๋ฆฌ์คํ
API
- ํด๋ผ์ด์ธํธ์์ ์ค ๋ฐ์ดํฐ: ์์
- ์๋ฒ์์ ํ ์ผ: ์ ๋ชฉ, ์ฝ๋ฉํธ๋ฅผ DB์์ ๋ชจ๋ ์ถ์ถ
- ์๋ฒ์์ ์ค ๊ฒ: ์ ๋ชฉ, ์ฝ๋ฉํธ ๊พธ๋ฌ๋ฏธ(๋ฆฌ์คํธ ํํ)