From f3cd9263a2a7739bb2bddb37f1b9ef194374be2d Mon Sep 17 00:00:00 2001 From: rubanap <33280996+rubanap@users.noreply.github.com> Date: Tue, 21 Nov 2017 12:22:54 +0530 Subject: [PATCH 1/7] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 36ae53b62..f9251bc12 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # ud036_StarterCode Source code for a Movie Trailer website. +# Prerequisite +Install Python +# Usage +1. Save all the python files given under movies folder in same location. +2. Open python IDLE +3. Go to `File->Open` and choose _EntertainmentCenter.py_ file +4. Press F5 to run the file +5. Play the movie trailer by clicking on the movie image displayed in the website + From 8aef00df7527ae0a291fda237e4fd9f00f1ce788 Mon Sep 17 00:00:00 2001 From: rubanap <33280996+rubanap@users.noreply.github.com> Date: Tue, 21 Nov 2017 12:23:51 +0530 Subject: [PATCH 2/7] Add files via upload --- EntertainmentCenter.py | 30 ++++ fresh_tomatoes.py | 325 ++++++++++++++++++++--------------------- media.py | 10 ++ 3 files changed, 198 insertions(+), 167 deletions(-) create mode 100644 EntertainmentCenter.py create mode 100644 media.py diff --git a/EntertainmentCenter.py b/EntertainmentCenter.py new file mode 100644 index 000000000..b28598f1a --- /dev/null +++ b/EntertainmentCenter.py @@ -0,0 +1,30 @@ +import media +import fresh_tomatoes +the_dark_knight=media.Movie("The Dark Knight", + "A man protecting his city disguised in bat suite", + "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3vVwDZYVjhrZsXQjhLkdZQAT9S6Irp6wSZhjO9S0rZZ-wjjPn", + "https://www.youtube.com/watch?v=EXeTwQWrcwY") +up=media.Movie("UP", + "An old man who is on the quest fo fulfilling his dead wife's wish and a kid who is struck around the old man are doing adventure things", + "https://vignette.wikia.nocookie.net/disney/images/a/a6/Up_Poster_Run.jpg/revision/latest?cb=20160202180816", + "https://www.youtube.com/watch?v=ZE_V0g9q4g0") +the_impossible=media.Movie("The impossible", + "How a family is getting reunited after Tsunami disaster ", + "https://upload.wikimedia.org/wikipedia/en/b/b8/The_Impossible.jpg", + "https://www.youtube.com/watch?v=Bgw394ZKsis") +harry_potter=media.Movie("The Harry Potter And The Sorcerer's Stone", + "A kid famous in wizard world attending wizard school", + "https://static.rogerebert.com/uploads/movie/movie_poster/harry-potter-and-the-sorcerers-stone-2001/large_uLGaJ9FgPWf7EUgwjp9RTmHemw8.jpg", + "https://www.youtube.com/watch?v=PbdM1db3JbY") +the_zootopia=media.Movie("The Zootopia", + "A bunny cop and wolf trying to catch the criminal gang", + "https://www.flayrah.com/sites/default/files/u/crossaffliction/zootopialittlegoldenbook.jpg", + "https://www.youtube.com/watch?v=jWM0ct-OLsM") +the_lord_of_rings=media.Movie("The_Lord_of_the_Rings: The_Fellowship_of_the_Ring", + "The fate of Middle-earth hangs in the balance as Frodo and eight companions who form the Fellowship of the Ring begin their journey to Mount Doom in the land of Mordor, the only place where the Ring can be destroyed.", + "https://upload.wikimedia.org/wikipedia/en/9/9d/The_Lord_of_the_Rings_The_Fellowship_of_the_Ring_%282001%29_theatrical_poster.jpg", + "https://www.youtube.com/watch?v=V75dMMIW2B4") + +movies=[the_dark_knight,up,the_impossible,harry_potter,the_zootopia,the_lord_of_rings] + +fresh_tomatoes.open_movies_page(movies) diff --git a/fresh_tomatoes.py b/fresh_tomatoes.py index 5cd75599c..3e2209b8c 100644 --- a/fresh_tomatoes.py +++ b/fresh_tomatoes.py @@ -1,167 +1,158 @@ -import webbrowser -import os -import re - - -# Styles and scripting for the page -main_page_head = ''' - - - - - Fresh Tomatoes! - - - - - - - - - -''' - - -# The main page layout and title bar -main_page_content = ''' - - - - - -
- -
-
- {movie_tiles} -
- - -''' - - -# A single movie entry html template -movie_tile_content = ''' -
- -

{movie_title}

-
-''' - - -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) +import webbrowser +import os +import re + +# Styles and scripting for the page +main_page_head = ''' + + + Fresh Tomatoes! + + + + + + + + + +''' + +# The main page layout and title bar +main_page_content = ''' + + + + + + + +
+ +
+
+ {movie_tiles} +
+ + +''' + +# A single movie entry html template +movie_tile_content = ''' +
+ +

{movie_title}

+
+''' + +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_id_match = youtube_id_match or re.search(r'(?<=be/)[^&#]+', movie.trailer) + 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, + 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 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() + + # 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 diff --git a/media.py b/media.py new file mode 100644 index 000000000..8c3e867f8 --- /dev/null +++ b/media.py @@ -0,0 +1,10 @@ +import webbrowser +class Movie(): + def __init__(self,movie_title,movie_storyline,poster_image,trailer_youtube): + self.title=movie_title + self.storyline=movie_storyline + self.poster=poster_image + self.trailer=trailer_youtube + + def show_trailor(self): + webbrowser.open(self.trailer) From 7c16ead162c9d47d44e04a2946dc10ac65aafa09 Mon Sep 17 00:00:00 2001 From: rubanap <33280996+rubanap@users.noreply.github.com> Date: Tue, 21 Nov 2017 12:24:31 +0530 Subject: [PATCH 3/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f9251bc12..10954e57c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Source code for a Movie Trailer website. # Prerequisite Install Python # Usage -1. Save all the python files given under movies folder in same location. +1. Save all the python files in same location. 2. Open python IDLE 3. Go to `File->Open` and choose _EntertainmentCenter.py_ file 4. Press F5 to run the file From 5820141e113f384f2b24a1395b8f7912f3770e7d Mon Sep 17 00:00:00 2001 From: rubanap <33280996+rubanap@users.noreply.github.com> Date: Tue, 21 Nov 2017 16:42:04 +0530 Subject: [PATCH 4/7] Update EntertainmentCenter.py --- EntertainmentCenter.py | 74 +++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/EntertainmentCenter.py b/EntertainmentCenter.py index b28598f1a..b0412c89d 100644 --- a/EntertainmentCenter.py +++ b/EntertainmentCenter.py @@ -1,30 +1,52 @@ import media import fresh_tomatoes -the_dark_knight=media.Movie("The Dark Knight", - "A man protecting his city disguised in bat suite", - "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3vVwDZYVjhrZsXQjhLkdZQAT9S6Irp6wSZhjO9S0rZZ-wjjPn", - "https://www.youtube.com/watch?v=EXeTwQWrcwY") -up=media.Movie("UP", - "An old man who is on the quest fo fulfilling his dead wife's wish and a kid who is struck around the old man are doing adventure things", - "https://vignette.wikia.nocookie.net/disney/images/a/a6/Up_Poster_Run.jpg/revision/latest?cb=20160202180816", - "https://www.youtube.com/watch?v=ZE_V0g9q4g0") -the_impossible=media.Movie("The impossible", - "How a family is getting reunited after Tsunami disaster ", - "https://upload.wikimedia.org/wikipedia/en/b/b8/The_Impossible.jpg", - "https://www.youtube.com/watch?v=Bgw394ZKsis") -harry_potter=media.Movie("The Harry Potter And The Sorcerer's Stone", - "A kid famous in wizard world attending wizard school", - "https://static.rogerebert.com/uploads/movie/movie_poster/harry-potter-and-the-sorcerers-stone-2001/large_uLGaJ9FgPWf7EUgwjp9RTmHemw8.jpg", - "https://www.youtube.com/watch?v=PbdM1db3JbY") -the_zootopia=media.Movie("The Zootopia", - "A bunny cop and wolf trying to catch the criminal gang", - "https://www.flayrah.com/sites/default/files/u/crossaffliction/zootopialittlegoldenbook.jpg", - "https://www.youtube.com/watch?v=jWM0ct-OLsM") -the_lord_of_rings=media.Movie("The_Lord_of_the_Rings: The_Fellowship_of_the_Ring", - "The fate of Middle-earth hangs in the balance as Frodo and eight companions who form the Fellowship of the Ring begin their journey to Mount Doom in the land of Mordor, the only place where the Ring can be destroyed.", - "https://upload.wikimedia.org/wikipedia/en/9/9d/The_Lord_of_the_Rings_The_Fellowship_of_the_Ring_%282001%29_theatrical_poster.jpg", - "https://www.youtube.com/watch?v=V75dMMIW2B4") - -movies=[the_dark_knight,up,the_impossible,harry_potter,the_zootopia,the_lord_of_rings] +the_dark_knight = media.Movie("The Dark Knight", + "A man protecting his city" + + "disguised in bat suite", + "https://encrypted-tbn0.gstatic.com/images?" + + "q=tbn:ANd9GcT3vVwDZYVjhrZsXQjhLkdZQAT9S6" + + "Irp6wSZhjO9S0rZZ-wjjPn", + "https://www.youtube.com/watch?v=EXeTwQWrcwY") +up = media.Movie("UP", + "An old man who is on the quest fo fulfilling" + + " his dead wife's wishand a kid who is struck around" + + " the old man are doing adventure things", + "https://vignette.wikia.nocookie.net/disney/" + + "images/a/a6/Up_Poster_Run.jpg/" + + "revision/latest?cb=20160202180816", + "https://www.youtube.com/watch?v=ZE_V0g9q4g0") +the_impossible = media.Movie("The impossible", + "How a family is getting reunited after" + + " Tsunami disaster ", + "https://upload.wikimedia.org/wikipedia/en" + + "/b/b8/The_Impossible.jpg", + "https://www.youtube.com/watch?v=Bgw394ZKsis") +harry_potter = media.Movie("The Harry Potter And The Sorcerer's Stone", + "A kid famous in wizard world" + + " attending wizard school", + "https://static.rogerebert.com/uploads/movie" + + "/movie_poster/harry-potter-and-the-sorcerers-" + + "stone-2001/large_uLGaJ9FgPWf7EUgwjp9RTmHemw8.jpg", + "https://www.youtube.com/watch?v=PbdM1db3JbY") +the_zootopia = media.Movie("The Zootopia", + "A bunny cop and wolf trying to" + + " catch the criminal gang", + "https://www.flayrah.com/sites/default/files/u/" + + "crossaffliction/zootopialittlegoldenbook.jpg", + "https://www.youtube.com/watch?v=jWM0ct-OLsM") +the_lord_of_rings = media.Movie("The_Lord_of_the_Rings:" + + "The_Fellowship_of_the_Ring", + "The fate of Middle-earth hangs in t" + + "he balance as Frodo and eight companions " + + " begin who form the Fellowship of the Ring" + + "their journey to Mount Doom in ," + + "the land of Mordor.", + "https://upload.wikimedia.org/wikipedia/en" + + "/9/9d/The_Lord_of_the_Rings_The_Fellowship" + + "_of_the_Ring_%282001%29_" + + "theatrical_poster.jpg", + "https://www.youtube.com/watch?v=V75dMMIW2B4") +movies = [the_dark_knight, up, the_impossible, harry_potter, + the_zootopia, the_lord_of_rings] fresh_tomatoes.open_movies_page(movies) From cb0ecc96e8e93bcda87470db438d4c8d79583d11 Mon Sep 17 00:00:00 2001 From: rubanap <33280996+rubanap@users.noreply.github.com> Date: Tue, 21 Nov 2017 16:43:06 +0530 Subject: [PATCH 5/7] Update media.py --- media.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/media.py b/media.py index 8c3e867f8..b5c6d4c7c 100644 --- a/media.py +++ b/media.py @@ -1,10 +1,13 @@ import webbrowser + + class Movie(): - def __init__(self,movie_title,movie_storyline,poster_image,trailer_youtube): - self.title=movie_title - self.storyline=movie_storyline - self.poster=poster_image - self.trailer=trailer_youtube + def __init__(self, movie_title, movie_storyline, + poster_image, trailer_youtube): + self.title = movie_title + self.storyline = movie_storyline + self.poster = poster_image + self.trailer = trailer_youtube def show_trailor(self): webbrowser.open(self.trailer) From 657cad73e826a1c0e2aeac9630702d71b351381f Mon Sep 17 00:00:00 2001 From: rubanap <33280996+rubanap@users.noreply.github.com> Date: Tue, 21 Nov 2017 17:11:06 +0530 Subject: [PATCH 6/7] Update EntertainmentCenter.py --- EntertainmentCenter.py | 100 +++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/EntertainmentCenter.py b/EntertainmentCenter.py index b0412c89d..a4a71b6b0 100644 --- a/EntertainmentCenter.py +++ b/EntertainmentCenter.py @@ -1,52 +1,56 @@ import media import fresh_tomatoes -the_dark_knight = media.Movie("The Dark Knight", - "A man protecting his city" + - "disguised in bat suite", - "https://encrypted-tbn0.gstatic.com/images?" + - "q=tbn:ANd9GcT3vVwDZYVjhrZsXQjhLkdZQAT9S6" + - "Irp6wSZhjO9S0rZZ-wjjPn", - "https://www.youtube.com/watch?v=EXeTwQWrcwY") -up = media.Movie("UP", - "An old man who is on the quest fo fulfilling" + - " his dead wife's wishand a kid who is struck around" + - " the old man are doing adventure things", - "https://vignette.wikia.nocookie.net/disney/" + - "images/a/a6/Up_Poster_Run.jpg/" + - "revision/latest?cb=20160202180816", - "https://www.youtube.com/watch?v=ZE_V0g9q4g0") -the_impossible = media.Movie("The impossible", - "How a family is getting reunited after" + - " Tsunami disaster ", - "https://upload.wikimedia.org/wikipedia/en" + - "/b/b8/The_Impossible.jpg", - "https://www.youtube.com/watch?v=Bgw394ZKsis") -harry_potter = media.Movie("The Harry Potter And The Sorcerer's Stone", - "A kid famous in wizard world" + - " attending wizard school", - "https://static.rogerebert.com/uploads/movie" + - "/movie_poster/harry-potter-and-the-sorcerers-" + - "stone-2001/large_uLGaJ9FgPWf7EUgwjp9RTmHemw8.jpg", - "https://www.youtube.com/watch?v=PbdM1db3JbY") -the_zootopia = media.Movie("The Zootopia", - "A bunny cop and wolf trying to" + - " catch the criminal gang", - "https://www.flayrah.com/sites/default/files/u/" + - "crossaffliction/zootopialittlegoldenbook.jpg", - "https://www.youtube.com/watch?v=jWM0ct-OLsM") -the_lord_of_rings = media.Movie("The_Lord_of_the_Rings:" + - "The_Fellowship_of_the_Ring", - "The fate of Middle-earth hangs in t" + - "he balance as Frodo and eight companions " + - " begin who form the Fellowship of the Ring" + - "their journey to Mount Doom in ," + - "the land of Mordor.", - "https://upload.wikimedia.org/wikipedia/en" + - "/9/9d/The_Lord_of_the_Rings_The_Fellowship" + - "_of_the_Ring_%282001%29_" + - "theatrical_poster.jpg", - "https://www.youtube.com/watch?v=V75dMMIW2B4") -movies = [the_dark_knight, up, the_impossible, harry_potter, - the_zootopia, the_lord_of_rings] +# Creating movie instances of Class Movie +the_dark_knight = media.Movie( + "The Dark Knight", + "A man protecting his city disguised in bat suite", + "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3vVwDZYVjhrZsXQjhLkdZQAT9S6Irp6wSZhjO9S0rZZ-wjjPn", # Noqa + "https://www.youtube.com/watch?v=EXeTwQWrcwY") +up = media.Movie( + "UP", + "An old man who is on the quest fo fulfilling his dead wife's" + + " wish and a kid who is struck around the old man are " + + "doing adventure things", + "https://vignette.wikia.nocookie.net/disney/images/a/a6/Up_Poster_Run.jpg/revision/latest?cb=20160202180816", # Noqa + "https://www.youtube.com/watch?v=ZE_V0g9q4g0") + +the_impossible = media.Movie( + "The impossible", + "How a family is getting reunited after Tsunami disaster ", + "https://upload.wikimedia.org/wikipedia/en/b/b8/The_Impossible.jpg", + "https://www.youtube.com/watch?v=Bgw394ZKsis") + +harry_potter = media.Movie( + "The Harry Potter And The Sorcerer's Stone", + "A kid famous in wizard world attending wizard school", + "https://static.rogerebert.com/uploads/movie/movie_poster/harry-potter-and-the-sorcerers-stone-2001/large_uLGaJ9FgPWf7EUgwjp9RTmHemw8.jpg", # Noqa + "https://www.youtube.com/watch?v=PbdM1db3JbY") + +the_zootopia = media.Movie( + "The Zootopia", + "A bunny cop and wolf trying to catch the criminal gang", + "https://www.flayrah.com/sites/default/files/u/crossaffliction/zootopialittlegoldenbook.jpg", # Noqa + "https://www.youtube.com/watch?v=jWM0ct-OLsM") + +the_lord_of_rings = media.Movie( + "The_Lord_of_the_Rings: The_Fellowship_of_the_Ring", + "The fate of Middle-earth hangs in the balance as Frodo and " + + "eight companions who form the Fellowship of the Ring begin " + + "their journey to Mount Doom in the land of Mordor", + "https://upload.wikimedia.org/wikipedia/en/9/9d/The_Lord_of_the_Rings_The_Fellowship_of_the_Ring_%282001%29_theatrical_poster.jpg", # Noqa + "https://www.youtube.com/watch?v=V75dMMIW2B4") + +# Movies array, contains the list of movies as input, which +# is passed to the function "open_movies_page". This function +# translates this list into a web page when we run the +# "EntertainmentCenter.py" file. + +movies = [the_dark_knight, + up, + the_impossible, + harry_potter, + the_zootopia, + the_lord_of_rings] +# Creating wepage with the movie instances to play trailer fresh_tomatoes.open_movies_page(movies) From 07ece85c440c151c4d922bf849fbdd7af2750bc1 Mon Sep 17 00:00:00 2001 From: rubanap <33280996+rubanap@users.noreply.github.com> Date: Tue, 21 Nov 2017 17:19:12 +0530 Subject: [PATCH 7/7] Update media.py --- media.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/media.py b/media.py index b5c6d4c7c..381358d63 100644 --- a/media.py +++ b/media.py @@ -2,12 +2,21 @@ class Movie(): + """ + Movie class to store the details of movie + """ def __init__(self, movie_title, movie_storyline, poster_image, trailer_youtube): + """ + Assign the movie instance variables with the given values + """ self.title = movie_title self.storyline = movie_storyline self.poster = poster_image self.trailer = trailer_youtube def show_trailor(self): + """ + Open the trailer of the calling movie instance + """ webbrowser.open(self.trailer)