-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
104 lines (78 loc) · 2.89 KB
/
app.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import certifi
import os
from flask import Flask, render_template, jsonify, request, redirect, url_for
from datetime import datetime
from pymongo import MongoClient
import crawling
app = Flask(__name__)
client = MongoClient(os.environ.get("MONGO"), tlsCAFile=certifi.where())
db = client.Sorting_Hat_Dev
# movies_list = list(db.movies.find({}, {'_id': False}))
# print(movies_list)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/recommend')
def recommend():
return render_template('recommend.html')
@app.route('/recommend/calc', methods=["POST"])
def recommend_calc():
movies_list = list(db.movies.find({'showing': 1}, {'_id': False}).sort('reviewer_star', -1))
rate_receive = int(request.form['give_rate'])
genre_receive = request.form.getlist('give_genre[]')
print(genre_receive, rate_receive)
for movie in movies_list:
print(movie)
if movie['age'] == '청소년 관람불가' and rate_receive < 3:
print('1번조건')
continue
elif movie['age'] == '15세 관람가' and rate_receive < 2:
print('2번조건')
continue
elif movie['age'] == '12세 관람가' and rate_receive < 1:
print('3번조건')
continue
else:
for m_genre in movie['genre']:
if genre_receive.count(m_genre) >= 1:
print(movie['title'])
return render_template('result.html', r_title=movie['title'], r_image=movie['image'])
return render_template('noresult.html')
@app.route('/schedule')
def schedule():
return render_template('schedule.html')
@app.route('/showing')
def showing():
return render_template('showing.html')
@app.route('/update', methods=["GET"])
def showing_get():
movies_list = list(db.movies.find({}, {}))
return jsonify({'movies': movies_list})
@app.route('/comment/get', methods=["GET"])
def comments_get():
print(request.args.get('m_id'))
comments_list = list(db.comments.find({'m_id': request.args.get('m_id')}, {'_id': False}).sort('time', -1))
print(comments_list)
return jsonify({'comments': comments_list})
@app.route('/comment/add', methods=["POST"])
def comments_add():
result = request.form
comment_time = datetime.now()
db.comments.insert_one(
{
'm_id': result.get('movie_id'),
'button': result.get('sel_btn'),
'user': result.get('u_name'),
'comment': result.get('comment'),
'time': comment_time,
}
)
return redirect(url_for(result.get('url')))
@app.route('/update_post', methods=["GET"])
def sca_get():
id = request.args.get('id')
movie = list(db.movies.find({'_id': id}, {}))
movie[0]['video_url'] = crawling.get_video(id, movie[0]['image'])
return jsonify({'movies': movie})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)