Skip to content

Commit

Permalink
Movie database Project udacity#1
Browse files Browse the repository at this point in the history
  • Loading branch information
sherinkuruvilla committed Jan 21, 2018
1 parent 28ae5de commit 201ee37
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions fresh_tomatoes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
import os
import re


# Styles and scripting for the page
main_page_head = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Fresh Tomatoes!</title>
Expand Down Expand Up @@ -85,9 +82,10 @@
</head>
'''


# The main page layout and title bar
main_page_content = '''
<!DOCTYPE html>
<html lang="en">
<body>
<!-- Trailer Video Modal -->
<div class="modal" id="trailer">
Expand All @@ -101,7 +99,7 @@
</div>
</div>
</div>
<!-- Main Page Content -->
<div class="container">
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
Expand All @@ -119,7 +117,6 @@
</html>
'''


# A single movie entry html template
movie_tile_content = '''
<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">
Expand All @@ -128,18 +125,14 @@
</div>
'''


def create_movie_tiles_content(movies):
# The HTML content for this section of the page
content = ''
for movie in movies:
# Extract the youtube ID from the url
youtube_id_match = re.search(
r'(?<=v=)[^&#]+', movie.trailer_youtube_url)
youtube_id_match = youtube_id_match or re.search(
r'(?<=be/)[^&#]+', movie.trailer_youtube_url)
trailer_youtube_id = (youtube_id_match.group(0) if youtube_id_match
else None)
youtube_id_match = re.search(r'(?<=v=)[^&#]+', movie.trailer_youtube_url)
youtube_id_match = youtube_id_match or re.search(r'(?<=be/)[^&#]+', movie.trailer_youtube_url)
trailer_youtube_id = youtube_id_match.group(0) if youtube_id_match else None

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


def open_movies_page(movies):
# Create or overwrite the output file
output_file = open('fresh_tomatoes.html', 'w')
# Create or overwrite the output file
output_file = open('fresh_tomatoes.html', 'w')

# Replace the movie tiles placeholder generated content
rendered_content = main_page_content.format(
movie_tiles=create_movie_tiles_content(movies))
# Replace the placeholder for the movie tiles with the actual dynamically generated content
rendered_content = main_page_content.format(movie_tiles=create_movie_tiles_content(movies))

# Output the file
output_file.write(main_page_head + rendered_content)
output_file.close()
# Output the file
output_file.write(main_page_head + rendered_content)
output_file.close()

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

0 comments on commit 201ee37

Please sign in to comment.