22import os
33import re
44
5-
65# Styles and scripting for the page
76main_page_head = '''
8- <!DOCTYPE html>
9- <html lang="en">
107<head>
118 <meta charset="utf-8">
129 <title>Fresh Tomatoes!</title>
8582</head>
8683'''
8784
88-
8985# The main page layout and title bar
9086main_page_content = '''
87+ <!DOCTYPE html>
88+ <html lang="en">
9189 <body>
9290 <!-- Trailer Video Modal -->
9391 <div class="modal" id="trailer">
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">
119117</html>
120118'''
121119
122-
123120# A single movie entry html template
124121movie_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">
128125</div>
129126'''
130127
131-
132128def 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-
153145def 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