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

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

@app.route("/")
def view():
    return render_template("jinja-quiz.html", values=movieList)

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 = dict()
        movie["rank"] = str(ranking)
        movie["title"] = tag.text.strip()
        movieList.append(movie)
        ranking = ranking + 1

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