Skip to content

Commit 201ee37

Browse files
author
sherinkuruvilla
committed
Movie database Project udacity#1
1 parent 28ae5de commit 201ee37

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

fresh_tomatoes.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
import os
33
import re
44

5-
65
# Styles and scripting for the page
76
main_page_head = '''
8-
<!DOCTYPE html>
9-
<html lang="en">
107
<head>
118
<meta charset="utf-8">
129
<title>Fresh Tomatoes!</title>
@@ -85,9 +82,10 @@
8582
</head>
8683
'''
8784

88-
8985
# The main page layout and title bar
9086
main_page_content = '''
87+
<!DOCTYPE html>
88+
<html lang="en">
9189
<body>
9290
<!-- Trailer Video Modal -->
9391
<div class="modal" id="trailer">
@@ -101,7 +99,7 @@
10199
</div>
102100
</div>
103101
</div>
104-
102+
105103
<!-- Main Page Content -->
106104
<div class="container">
107105
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
@@ -119,7 +117,6 @@
119117
</html>
120118
'''
121119

122-
123120
# A single movie entry html template
124121
movie_tile_content = '''
125122
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="{trailer_youtube_id}" data-toggle="modal" data-target="#trailer">
@@ -128,18 +125,14 @@
128125
</div>
129126
'''
130127

131-
132128
def create_movie_tiles_content(movies):
133129
# The HTML content for this section of the page
134130
content = ''
135131
for movie in movies:
136132
# Extract the youtube ID from the url
137-
youtube_id_match = re.search(
138-
r'(?<=v=)[^&#]+', movie.trailer_youtube_url)
139-
youtube_id_match = youtube_id_match or re.search(
140-
r'(?<=be/)[^&#]+', movie.trailer_youtube_url)
141-
trailer_youtube_id = (youtube_id_match.group(0) if youtube_id_match
142-
else None)
133+
youtube_id_match = re.search(r'(?<=v=)[^&#]+', movie.trailer_youtube_url)
134+
youtube_id_match = youtube_id_match or re.search(r'(?<=be/)[^&#]+', movie.trailer_youtube_url)
135+
trailer_youtube_id = youtube_id_match.group(0) if youtube_id_match else None
143136

144137
# Append the tile for the movie with its content filled in
145138
content += movie_tile_content.format(
@@ -149,19 +142,17 @@ def create_movie_tiles_content(movies):
149142
)
150143
return content
151144

152-
153145
def open_movies_page(movies):
154-
# Create or overwrite the output file
155-
output_file = open('fresh_tomatoes.html', 'w')
146+
# Create or overwrite the output file
147+
output_file = open('fresh_tomatoes.html', 'w')
156148

157-
# Replace the movie tiles placeholder generated content
158-
rendered_content = main_page_content.format(
159-
movie_tiles=create_movie_tiles_content(movies))
149+
# Replace the placeholder for the movie tiles with the actual dynamically generated content
150+
rendered_content = main_page_content.format(movie_tiles=create_movie_tiles_content(movies))
160151

161-
# Output the file
162-
output_file.write(main_page_head + rendered_content)
163-
output_file.close()
152+
# Output the file
153+
output_file.write(main_page_head + rendered_content)
154+
output_file.close()
164155

165-
# open the output file in the browser (in a new tab, if possible)
166-
url = os.path.abspath(output_file.name)
167-
webbrowser.open('file://' + url, new=2)
156+
# open the output file in the browser
157+
url = os.path.abspath(output_file.name)
158+
webbrowser.open('file://' + url, new=2) # open in a new tab, if possible

0 commit comments

Comments
 (0)