Skip to content

Commit a3390ae

Browse files
committed
feat: select movie from tmdb api
1 parent 6a3a410 commit a3390ae

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

Diff for: TopMovieList/app.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
from wtforms.validators import DataRequired
77
import requests
88

9+
# CONSTANTS
10+
11+
MOVIE_DB_API_KEY = "YOUR API KEY"
12+
MOVIE_DB_SEARCH_URL = "https://api.themoviedb.org/3/search/movie"
13+
MOVIE_DB_INFO_URL = "https://api.themoviedb.org/3/movie"
14+
MOVIE_DB_IMAGE_URL = "https://image.tmdb.org/t/p/w500"
15+
916
app = Flask(__name__)
1017

1118
# secret key
1219
app.secret_key = b'\xb9\xd6\xc7\xc4\xb5\xf0\xc4y\xc6\xb0\r\xc3`!\xca~'
13-
20+
# flask bootstrap
1421
Bootstrap(app)
1522

1623
# creating db
@@ -84,6 +91,13 @@ def delete_movie():
8491
@app.route('/add', methods=["GET", "POST"])
8592
def add_movie():
8693
form = FindMovieForm()
94+
95+
# get information from The Movie database
96+
if form.validate_on_submit():
97+
movie_title = form.title.data
98+
response = requests.get(MOVIE_DB_SEARCH_URL, params={"api_key": MOVIE_DB_API_KEY, "query": movie_title})
99+
data = response.json()["results"]
100+
return render_template("select.html", options=data)
87101
return render_template("add.html", form=form)
88102

89103

Diff for: TopMovieList/templates/select.html

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{% extends 'bootstrap/base.html' %}
2+
{% import 'bootstrap/wtf.html' as wtf %}
3+
4+
{% block styles %}
5+
{{ super() }}
6+
7+
<!-- Google Fonts -->
8+
9+
<link
10+
rel="stylesheet"
11+
href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,700"
12+
/>
13+
<link
14+
rel="stylesheet"
15+
href="https://fonts.googleapis.com/css?family=Poppins:300,400,700"
16+
/>
17+
<link
18+
rel="stylesheet"
19+
href="https://fonts.googleapis.com/css?family=Poppins:300,400,700"
20+
/>
21+
22+
<!-- Font Awesome CSS -->
23+
<link
24+
rel="stylesheet"
25+
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
26+
integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
27+
crossorigin="anonymous"
28+
/>
29+
30+
<!-- Custom CSS Styling -->
31+
<link
32+
rel="stylesheet"
33+
href="{{ url_for('static', filename='css/styles.css') }}"
34+
/>
35+
{% endblock %}
36+
37+
{% block title %} Select Movies {% endblock %}
38+
39+
{% block content %}
40+
<div class="container">
41+
42+
<div class="content">
43+
<h1 class="heading">Select Movie</h1>
44+
45+
46+
<div class="card" style="width: 18rem;">
47+
<div class="card-header">
48+
Select A Movie
49+
</div>
50+
{% for movie in options: %}
51+
<ul class="list-group list-group-flush">
52+
<li class="list-group-item">{{ movie.title }} | ({{ movie.release_date }})</li>
53+
</ul>
54+
{% endfor %}
55+
</div>
56+
57+
58+
</div>
59+
60+
</div>
61+
{% endblock %}

0 commit comments

Comments
 (0)