Skip to content

Commit

Permalink
PEP8 standards met
Browse files Browse the repository at this point in the history
  • Loading branch information
adarsh0806 committed Jul 6, 2015
1 parent e351159 commit e380e73
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions fresh_tomatoes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import re


# Styles and scripting for the page
main_page_head = '''
<head>
Expand Down Expand Up @@ -82,6 +83,7 @@
</head>
'''


# The main page layout and title bar
main_page_content = '''
<!DOCTYPE html>
Expand All @@ -99,7 +101,7 @@
</div>
</div>
</div>
<!-- Main Page Content -->
<div class="container">
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
Expand All @@ -117,6 +119,7 @@
</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 @@ -125,14 +128,18 @@
</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 @@ -142,17 +149,19 @@ 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 placeholder for the movie tiles with the actual dynamically generated content
rendered_content = main_page_content.format(movie_tiles=create_movie_tiles_content(movies))
# Replace the movie tiles placeholder 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
url = os.path.abspath(output_file.name)
webbrowser.open('file://' + url, new=2) # open in a new tab, if possible
# 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)

0 comments on commit e380e73

Please sign in to comment.