Created
February 1, 2016 08:15
-
-
Save fer408/a41b670f3981faf7cad2 to your computer and use it in GitHub Desktop.
Intro to programming Project 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#allows for this code to be viewed in a static webpage. | |
import fresh_tomatoes | |
#allows me to use the class Movie. | |
import media | |
#following is code for my favorite movies. | |
#code for toy story. | |
toy_story = media.Movie("Toy Story", | |
"A story of a boy and his toys that come to life", | |
"https://en.wikipedia.org/wiki/Toy_Story#/media/File:Toy_Story.jpg", | |
"https://www.youtube.com/watch?v=4KPTXpQehio") | |
#code for avatar. | |
avatar = media.Movie("Avatar", | |
"A marine on a alien planet", | |
"https://en.wikipedia.org/wiki/Avatar_(2009_film)#/media/File:Avatar-Teaser-Poster.jpg", | |
"https://www.youtube.com/watch?v=5PSNL1qE6VY") | |
#code for forrest gump. | |
forrest_gump = media.Movie("Forrest Gump", | |
"An epic tale of a mans amazing journey trough life", | |
"https://en.wikipedia.org/wiki/Forrest_Gump#/media/File:Forrest_Gump_poster.jpg", | |
"https://www.youtube.com/watch?v=YNh9Es8Ut6U") | |
#code for batman begins. | |
batman_begins = media.Movie("Batman", | |
"A story of a rich orphan who fights crime", | |
"https://en.wikipedia.org/wiki/Batman_Begins#/media/File:Batman_Begins_Poster.jpg", | |
"https://www.youtube.com/watch?v=neY2xVmOfUM") | |
# code for half baked. | |
half_baked = media.Movie("Half Baked", | |
"A story of a group of stoners who try to get their friend out the joint", | |
"https://en.wikipedia.org/wiki/Half_Baked#/media/File:Half-baked-dvd-cover.jpg", | |
"https://www.youtube.com/watch?v=-O4wMW1-tkY") | |
# code for jaws. | |
jaws = media.Movie("Jaws", | |
"A story about a giant killer shark", | |
"https://en.wikipedia.org/wiki/Jaws_(film)#/media/File:JAWS_Movie_poster.jpg", | |
"https://www.youtube.com/watch?v=U1fu_sA7XhE") | |
#code for joe dirt. | |
joe_dirt = media.Movie("Joe dirt", | |
"A Hillbilly tries to find his parents but ends up finding family in other places", | |
"https://en.wikipedia.org/wiki/Joe_Dirt#/media/File:Joe_dirt.jpg", | |
"https://www.youtube.com/watch?v=FpHIIE9Lois") | |
#code for fight club | |
fight_club = media.Movie("Fight Club", | |
"a weak regular man ends up finding himself trough beating up his buddies in a secret club", | |
"https://en.wikipedia.org/wiki/Fight_Club#/media/File:Fight_Club_poster.jpg", | |
"https://www.youtube.com/watch?v=SUXWAEX2jlg") | |
movies = [toy_story,avatar,forrest_gump,batman_begins,half_baked,jaws,joe_dirt,fight_club] | |
#code that makes it all happen | |
fresh_tomatoes.open_movies_page(movies) | |
#print (media.Movie.VALID_RATINGS) | |
#print(media.Movie.__doc__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Fresh Tomatoes!</title> | |
<!-- Bootstrap 3 --> | |
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css"> | |
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script> | |
<style type="text/css" media="screen"> | |
body { | |
padding-top: 80px; | |
} | |
#trailer .modal-dialog { | |
margin-top: 200px; | |
width: 640px; | |
height: 480px; | |
} | |
.hanging-close { | |
position: absolute; | |
top: -12px; | |
right: -12px; | |
z-index: 9001; | |
} | |
#trailer-video { | |
width: 100%; | |
height: 100%; | |
} | |
.movie-tile { | |
margin-bottom: 20px; | |
padding-top: 20px; | |
} | |
.movie-tile:hover { | |
background-color: #EEE; | |
cursor: pointer; | |
} | |
.scale-media { | |
padding-bottom: 56.25%; | |
position: relative; | |
} | |
.scale-media iframe { | |
border: none; | |
height: 100%; | |
position: absolute; | |
width: 100%; | |
left: 0; | |
top: 0; | |
background-color: white; | |
} | |
</style> | |
<script type="text/javascript" charset="utf-8"> | |
// Pause the video when the modal is closed | |
$(document).on('click', '.hanging-close, .modal-backdrop, .modal', function (event) { | |
// Remove the src so the player itself gets removed, as this is the only | |
// reliable way to ensure the video stops playing in IE | |
$("#trailer-video-container").empty(); | |
}); | |
// Start playing the video whenever the trailer modal is opened | |
$(document).on('click', '.movie-tile', function (event) { | |
var trailerYouTubeId = $(this).attr('data-trailer-youtube-id') | |
var sourceUrl = 'http://www.youtube.com/embed/' + trailerYouTubeId + '?autoplay=1&html5=1'; | |
$("#trailer-video-container").empty().append($("<iframe></iframe>", { | |
'id': 'trailer-video', | |
'type': 'text-html', | |
'src': sourceUrl, | |
'frameborder': 0 | |
})); | |
}); | |
// Animate in the movies when the page loads | |
$(document).ready(function () { | |
$('.movie-tile').hide().first().show("fast", function showNext() { | |
$(this).next("div").show("fast", showNext); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<!-- Trailer Video Modal --> | |
<div class="modal" id="trailer"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<a href="#" class="hanging-close" data-dismiss="modal" aria-hidden="true"> | |
<img src="https://lh5.ggpht.com/v4-628SilF0HtHuHdu5EzxD7WRqOrrTIDi_MhEG6_qkNtUK5Wg7KPkofp_VJoF7RS2LhxwEFCO1ICHZlc-o_=s0#w=24&h=24"/> | |
</a> | |
<div class="scale-media" id="trailer-video-container"> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Main Page Content --> | |
<div class="container"> | |
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> | |
<div class="container"> | |
<div class="navbar-header"> | |
<a class="navbar-brand" href="#">Fresh Tomatoes Movie Trailers</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="container"> | |
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="4KPTXpQehio" data-toggle="modal" data-target="#trailer"> | |
<img src="https://en.wikipedia.org/wiki/Toy_Story#/media/File:Toy_Story.jpg" width="220" height="342"> | |
<h2>Toy Story</h2> | |
</div> | |
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="5PSNL1qE6VY" data-toggle="modal" data-target="#trailer"> | |
<img src="https://en.wikipedia.org/wiki/Avatar_(2009_film)#/media/File:Avatar-Teaser-Poster.jpg" width="220" height="342"> | |
<h2>Avatar</h2> | |
</div> | |
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="YNh9Es8Ut6U" data-toggle="modal" data-target="#trailer"> | |
<img src="https://en.wikipedia.org/wiki/Forrest_Gump#/media/File:Forrest_Gump_poster.jpg" width="220" height="342"> | |
<h2>Forrest Gump</h2> | |
</div> | |
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="neY2xVmOfUM" data-toggle="modal" data-target="#trailer"> | |
<img src="https://en.wikipedia.org/wiki/Batman_Begins#/media/File:Batman_Begins_Poster.jpg" width="220" height="342"> | |
<h2>Batman</h2> | |
</div> | |
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="-O4wMW1-tkY" data-toggle="modal" data-target="#trailer"> | |
<img src="https://en.wikipedia.org/wiki/Half_Baked#/media/File:Half-baked-dvd-cover.jpg" width="220" height="342"> | |
<h2>Half Baked</h2> | |
</div> | |
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="U1fu_sA7XhE" data-toggle="modal" data-target="#trailer"> | |
<img src="https://en.wikipedia.org/wiki/Jaws_(film)#/media/File:JAWS_Movie_poster.jpg" width="220" height="342"> | |
<h2>Jaws</h2> | |
</div> | |
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="FpHIIE9Lois" data-toggle="modal" data-target="#trailer"> | |
<img src="https://en.wikipedia.org/wiki/Joe_Dirt#/media/File:Joe_dirt.jpg" width="220" height="342"> | |
<h2>Joe dirt</h2> | |
</div> | |
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="SUXWAEX2jlg" data-toggle="modal" data-target="#trailer"> | |
<img src="https://en.wikipedia.org/wiki/Fight_Club#/media/File:Fight_Club_poster.jpg" width="220" height="342"> | |
<h2>Fight Club</h2> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this code allows for the other python code to be viewed in a web browser | |
import webbrowser | |
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> | |
<!-- Bootstrap 3 --> | |
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css"> | |
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script> | |
<style type="text/css" media="screen"> | |
body { | |
padding-top: 80px; | |
} | |
#trailer .modal-dialog { | |
margin-top: 200px; | |
width: 640px; | |
height: 480px; | |
} | |
.hanging-close { | |
position: absolute; | |
top: -12px; | |
right: -12px; | |
z-index: 9001; | |
} | |
#trailer-video { | |
width: 100%; | |
height: 100%; | |
} | |
.movie-tile { | |
margin-bottom: 20px; | |
padding-top: 20px; | |
} | |
.movie-tile:hover { | |
background-color: #EEE; | |
cursor: pointer; | |
} | |
.scale-media { | |
padding-bottom: 56.25%; | |
position: relative; | |
} | |
.scale-media iframe { | |
border: none; | |
height: 100%; | |
position: absolute; | |
width: 100%; | |
left: 0; | |
top: 0; | |
background-color: white; | |
} | |
</style> | |
<script type="text/javascript" charset="utf-8"> | |
// Pause the video when the modal is closed | |
$(document).on('click', '.hanging-close, .modal-backdrop, .modal', function (event) { | |
// Remove the src so the player itself gets removed, as this is the only | |
// reliable way to ensure the video stops playing in IE | |
$("#trailer-video-container").empty(); | |
}); | |
// Start playing the video whenever the trailer modal is opened | |
$(document).on('click', '.movie-tile', function (event) { | |
var trailerYouTubeId = $(this).attr('data-trailer-youtube-id') | |
var sourceUrl = 'http://www.youtube.com/embed/' + trailerYouTubeId + '?autoplay=1&html5=1'; | |
$("#trailer-video-container").empty().append($("<iframe></iframe>", { | |
'id': 'trailer-video', | |
'type': 'text-html', | |
'src': sourceUrl, | |
'frameborder': 0 | |
})); | |
}); | |
// Animate in the movies when the page loads | |
$(document).ready(function () { | |
$('.movie-tile').hide().first().show("fast", function showNext() { | |
$(this).next("div").show("fast", showNext); | |
}); | |
}); | |
</script> | |
</head> | |
''' | |
# The main page layout and title bar | |
main_page_content = ''' | |
<body> | |
<!-- Trailer Video Modal --> | |
<div class="modal" id="trailer"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<a href="#" class="hanging-close" data-dismiss="modal" aria-hidden="true"> | |
<img src="https://lh5.ggpht.com/v4-628SilF0HtHuHdu5EzxD7WRqOrrTIDi_MhEG6_qkNtUK5Wg7KPkofp_VJoF7RS2LhxwEFCO1ICHZlc-o_=s0#w=24&h=24"/> | |
</a> | |
<div class="scale-media" id="trailer-video-container"> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Main Page Content --> | |
<div class="container"> | |
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> | |
<div class="container"> | |
<div class="navbar-header"> | |
<a class="navbar-brand" href="#">Fresh Tomatoes Movie Trailers</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="container"> | |
{movie_tiles} | |
</div> | |
</body> | |
</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"> | |
<img src="{poster_image_url}" width="220" height="342"> | |
<h2>{movie_title}</h2> | |
</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) | |
# Append the tile for the movie with its content filled in | |
content += movie_tile_content.format( | |
movie_title=movie.title, | |
poster_image_url=movie.poster_image_url, | |
trailer_youtube_id=trailer_youtube_id | |
) | |
return content | |
def open_movies_page(movies): | |
# 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)) | |
# 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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#code that allows the trailer to be viewed on the web brower. | |
import webbrowser | |
# this is the class Movie which is the foundation for everything. | |
class Movie(): | |
"""This class alows for movie information to be stored.""" | |
VALID_RATINGS = ["G","PG","PG-13","R"] | |
# this function is the base for the Movie objects. | |
def __init__(self,movie_title,movie_storyline,poster_image,trailer_youtube): | |
self.title = movie_title | |
self.storyline = movie_storyline | |
self.poster_image_url = poster_image | |
self.trailer_youtube_url = trailer_youtube | |
#this function allows for trailers to be showed. | |
def show_trailer(self): | |
webbrowser.open(self.trailer_youtube_url) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment