Skip to content

Commit 86b8449

Browse files
#
1 parent 2252450 commit 86b8449

File tree

6 files changed

+363
-0
lines changed

6 files changed

+363
-0
lines changed

entertainment.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import media
2+
import fresh_tomatoes
3+
4+
chakras = media.Movie("7 Chakras",
5+
"How To Open Your 7 Chakras Explained",
6+
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg",
7+
"https://www.youtube.com/watch?v=StrbppmsZJw"
8+
)
9+
#print(chakras.storyline)
10+
11+
chakras1 = media.Movie("7 Chakras",
12+
"How To Open Your 7 Chakras Explained",
13+
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg",
14+
"https://www.youtube.com/watch?v=StrbppmsZJw"
15+
)
16+
#print(chakras1.storyline)
17+
18+
chakras2 = media.Movie("7 Chakras",
19+
"How To Open Your 7 Chakras Explained",
20+
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg",
21+
"https://www.youtube.com/watch?v=StrbppmsZJw"
22+
)
23+
#print(chakras2.storyline)
24+
25+
chakras3 = media.Movie("7 Chakras",
26+
"How To Open Your 7 Chakras Explained",
27+
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg",
28+
"https://www.youtube.com/watch?v=StrbppmsZJw"
29+
)
30+
#print(chakras3.storyline)
31+
32+
chakras4 = media.Movie("7 Chakras",
33+
"How To Open Your 7 Chakras Explained",
34+
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg",
35+
"https://www.youtube.com/watch?v=StrbppmsZJw"
36+
)
37+
38+
chakras5 = media.Movie("7 Chakras",
39+
"How To Open Your 7 Chakras Explained",
40+
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg",
41+
"https://www.youtube.com/watch?v=StrbppmsZJw"
42+
)
43+
44+
movies = [chakras, chakras1, chakras2, chakras3, chakras4, chakras5]
45+
fresh_tomatoes.open_movies_page(movies)
46+
#chakras.show_trailer()
47+
48+
49+

fresh_tomatoes.html

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Videos !!</title>
7+
<!-- Bootstrap 3 -->
8+
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
9+
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
10+
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
11+
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
12+
<style type="text/css" media="screen">
13+
body {
14+
padding-top: 80px;
15+
}
16+
#trailer .modal-dialog {
17+
margin-top: 200px;
18+
width: 640px;
19+
height: 480px;
20+
}
21+
.hanging-close {
22+
position: absolute;
23+
top: -12px;
24+
right: -12px;
25+
z-index: 9001;
26+
}
27+
#trailer-video {
28+
width: 100%;
29+
height: 100%;
30+
}
31+
.movie-tile {
32+
margin-bottom: 20px;
33+
padding-top: 20px;
34+
}
35+
.movie-tile:hover {
36+
background-color: #EEE;
37+
cursor: pointer;
38+
}
39+
.scale-media {
40+
padding-bottom: 56.25%;
41+
position: relative;
42+
}
43+
.scale-media iframe {
44+
border: none;
45+
height: 100%;
46+
position: absolute;
47+
width: 100%;
48+
left: 0;
49+
top: 0;
50+
background-color: white;
51+
}
52+
</style>
53+
<script type="text/javascript" charset="utf-8">
54+
// Pause the video when the modal is closed
55+
$(document).on('click', '.hanging-close, .modal-backdrop, .modal', function (event) {
56+
// Remove the src so the player itself gets removed, as this is the only
57+
// reliable way to ensure the video stops playing in IE
58+
$("#trailer-video-container").empty();
59+
});
60+
// Start playing the video whenever the trailer modal is opened
61+
$(document).on('click', '.movie-tile', function (event) {
62+
var trailerYouTubeId = $(this).attr('data-trailer-youtube-id')
63+
var sourceUrl = 'http://www.youtube.com/embed/' + trailerYouTubeId + '?autoplay=1&html5=1';
64+
$("#trailer-video-container").empty().append($("<iframe></iframe>", {
65+
'id': 'trailer-video',
66+
'type': 'text-html',
67+
'src': sourceUrl,
68+
'frameborder': 0
69+
}));
70+
});
71+
// Animate in the movies when the page loads
72+
$(document).ready(function () {
73+
$('.movie-tile').hide().first().show("fast", function showNext() {
74+
$(this).next("div").show("fast", showNext);
75+
});
76+
});
77+
</script>
78+
</head>
79+
80+
<body>
81+
<!-- Trailer Video Modal -->
82+
<div class="modal" id="trailer">
83+
<div class="modal-dialog">
84+
<div class="modal-content">
85+
<a href="#" class="hanging-close" data-dismiss="modal" aria-hidden="true">
86+
<img src="https://lh5.ggpht.com/v4-628SilF0HtHuHdu5EzxD7WRqOrrTIDi_MhEG6_qkNtUK5Wg7KPkofp_VJoF7RS2LhxwEFCO1ICHZlc-o_=s0#w=24&h=24"/>
87+
</a>
88+
<div class="scale-media" id="trailer-video-container">
89+
</div>
90+
</div>
91+
</div>
92+
</div>
93+
<!-- Main Page Content -->
94+
<div class="container">
95+
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
96+
<div class="container">
97+
<div class="navbar-header">
98+
<a class="navbar-brand" href="#">Videos worth watching :)</a>
99+
</div>
100+
</div>
101+
</div>
102+
</div>
103+
<div class="container">
104+
105+
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="StrbppmsZJw" data-toggle="modal" data-target="#trailer">
106+
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg" width="220" height="342">
107+
<h2>7 Chakras</h2>
108+
</div>
109+
110+
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="StrbppmsZJw" data-toggle="modal" data-target="#trailer">
111+
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg" width="220" height="342">
112+
<h2>7 Chakras</h2>
113+
</div>
114+
115+
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="StrbppmsZJw" data-toggle="modal" data-target="#trailer">
116+
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg" width="220" height="342">
117+
<h2>7 Chakras</h2>
118+
</div>
119+
120+
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="StrbppmsZJw" data-toggle="modal" data-target="#trailer">
121+
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg" width="220" height="342">
122+
<h2>7 Chakras</h2>
123+
</div>
124+
125+
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="StrbppmsZJw" data-toggle="modal" data-target="#trailer">
126+
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg" width="220" height="342">
127+
<h2>7 Chakras</h2>
128+
</div>
129+
130+
<div class="col-md-6 col-lg-4 movie-tile text-center" data-trailer-youtube-id="StrbppmsZJw" data-toggle="modal" data-target="#trailer">
131+
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTM3MTc3OTc0NF5BMl5BanBnXkFtZTcwOTQ0OTM1MQ@@._V1._CR34,0,295,440_UX182_CR0,0,182,268_AL__QL50.jpg" width="220" height="342">
132+
<h2>7 Chakras</h2>
133+
</div>
134+
135+
</div>
136+
</body>
137+
</html>

fresh_tomatoes.py

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import webbrowser
2+
import os
3+
import re
4+
5+
6+
# Styles and scripting for the page
7+
main_page_head = '''
8+
<!DOCTYPE html>
9+
<html lang="en">
10+
<head>
11+
<meta charset="utf-8">
12+
<title>Videos !</title>
13+
<!-- Bootstrap 3 -->
14+
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
15+
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
16+
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
17+
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
18+
<style type="text/css" media="screen">
19+
body {
20+
padding-top: 80px;
21+
}
22+
#trailer .modal-dialog {
23+
margin-top: 200px;
24+
width: 640px;
25+
height: 480px;
26+
}
27+
.hanging-close {
28+
position: absolute;
29+
top: -12px;
30+
right: -12px;
31+
z-index: 9001;
32+
}
33+
#trailer-video {
34+
width: 100%;
35+
height: 100%;
36+
}
37+
.movie-tile {
38+
margin-bottom: 20px;
39+
padding-top: 20px;
40+
}
41+
.movie-tile:hover {
42+
background-color: #EEE;
43+
cursor: pointer;
44+
}
45+
.scale-media {
46+
padding-bottom: 56.25%;
47+
position: relative;
48+
}
49+
.scale-media iframe {
50+
border: none;
51+
height: 100%;
52+
position: absolute;
53+
width: 100%;
54+
left: 0;
55+
top: 0;
56+
background-color: white;
57+
}
58+
</style>
59+
<script type="text/javascript" charset="utf-8">
60+
// Pause the video when the modal is closed
61+
$(document).on('click', '.hanging-close, .modal-backdrop, .modal', function (event) {
62+
// Remove the src so the player itself gets removed, as this is the only
63+
// reliable way to ensure the video stops playing in IE
64+
$("#trailer-video-container").empty();
65+
});
66+
// Start playing the video whenever the trailer modal is opened
67+
$(document).on('click', '.movie-tile', function (event) {
68+
var trailerYouTubeId = $(this).attr('data-trailer-youtube-id')
69+
var sourceUrl = 'http://www.youtube.com/embed/' + trailerYouTubeId + '?autoplay=1&html5=1';
70+
$("#trailer-video-container").empty().append($("<iframe></iframe>", {
71+
'id': 'trailer-video',
72+
'type': 'text-html',
73+
'src': sourceUrl,
74+
'frameborder': 0
75+
}));
76+
});
77+
// Animate in the movies when the page loads
78+
$(document).ready(function () {
79+
$('.movie-tile').hide().first().show("fast", function showNext() {
80+
$(this).next("div").show("fast", showNext);
81+
});
82+
});
83+
</script>
84+
</head>
85+
'''
86+
87+
88+
# The main page layout and title bar
89+
main_page_content = '''
90+
<body>
91+
<!-- Trailer Video Modal -->
92+
<div class="modal" id="trailer">
93+
<div class="modal-dialog">
94+
<div class="modal-content">
95+
<a href="#" class="hanging-close" data-dismiss="modal" aria-hidden="true">
96+
<img src="https://lh5.ggpht.com/v4-628SilF0HtHuHdu5EzxD7WRqOrrTIDi_MhEG6_qkNtUK5Wg7KPkofp_VJoF7RS2LhxwEFCO1ICHZlc-o_=s0#w=24&h=24"/>
97+
</a>
98+
<div class="scale-media" id="trailer-video-container">
99+
</div>
100+
</div>
101+
</div>
102+
</div>
103+
<!-- Main Page Content -->
104+
<div class="container">
105+
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
106+
<div class="container">
107+
<div class="navbar-header">
108+
<a class="navbar-brand" href="#"> Videos worth watching :)</a>
109+
</div>
110+
</div>
111+
</div>
112+
</div>
113+
<div class="container">
114+
{movie_tiles}
115+
</div>
116+
</body>
117+
</html>
118+
'''
119+
120+
121+
# A single movie entry html template
122+
movie_tile_content = '''
123+
<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">
124+
<img src="{poster_image_url}" width="220" height="342">
125+
<h2>{movie_title}</h2>
126+
</div>
127+
'''
128+
129+
130+
def create_movie_tiles_content(movies):
131+
# The HTML content for this section of the page
132+
content = ''
133+
for movie in movies:
134+
# Extract the youtube ID from the url
135+
youtube_id_match = re.search(
136+
r'(?<=v=)[^&#]+', movie.trailer_youtube_url)
137+
youtube_id_match = youtube_id_match or re.search(
138+
r'(?<=be/)[^&#]+', movie.trailer_youtube_url)
139+
trailer_youtube_id = (youtube_id_match.group(0) if youtube_id_match
140+
else None)
141+
142+
# Append the tile for the movie with its content filled in
143+
content += movie_tile_content.format(
144+
movie_title=movie.title,
145+
poster_image_url=movie.poster_image_url,
146+
trailer_youtube_id=trailer_youtube_id
147+
)
148+
return content
149+
150+
151+
def open_movies_page(movies):
152+
# Create or overwrite the output file
153+
output_file = open('fresh_tomatoes.html', 'w')
154+
155+
# Replace the movie tiles placeholder generated content
156+
rendered_content = main_page_content.format(
157+
movie_tiles=create_movie_tiles_content(movies))
158+
159+
# Output the file
160+
output_file.write(main_page_head + rendered_content)
161+
output_file.close()
162+
163+
# open the output file in the browser (in a new tab, if possible)
164+
url = os.path.abspath(output_file.name)
165+
webbrowser.open('file://' + url, new=2)

fresh_tomatoes.pyc

5.23 KB
Binary file not shown.

media.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import webbrowser
2+
3+
class Movie():
4+
5+
def __init__(self,movie_title,movie_story_line,movie_image,movie_video):
6+
self.title=movie_title
7+
self.storyline=movie_story_line
8+
self.poster_image_url=movie_image
9+
self.trailer_youtube_url=movie_video
10+
11+
def show_trailer(self):
12+
webbrowser.open(self.trailer_youtube_url)

media.pyc

721 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)