from flask import Flask, jsonify
import requests
from bs4 import BeautifulSoup

movie = dict()
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False

@app.route("/")
def view():
    data = jsonify(movie)
    return data    # 일반 텍스트 형식으로 데이터를 전달

def naverMovie():
    response = requests.get('https://movie.naver.com/movie/sdb/rank/rmovie.nhn')
    html = response.text
    soup = BeautifulSoup(html, 'html.parser')
    ranking = 1

    for tag in soup.select('div[class=tit3]'):
        url = tag.get('href')
        movie[str(ranking)+'위'] = tag.text.strip()
        ranking = ranking + 1

if __name__ == "__main__":
    naverMovie()
    app.run(host="127.0.0.1", port="8080")