Skip to content

Commit c076c6e

Browse files
committed
Practice
1 parent 8b48e5c commit c076c6e

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

Day17/q58.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
# Write a Python program to get movie name, year and a brief summary of the top 10 random movies.
3+
4+
__author__ = "Mahtab Alam"
5+
6+
from bs4 import BeautifulSoup
7+
import requests
8+
import random
9+
10+
11+
def get_imd_movies(url):
12+
page = requests.get(url)
13+
soup = BeautifulSoup(page.text, 'html.parser')
14+
movies = soup.find_all("td", class_="titleColumn")
15+
random.shuffle(movies)
16+
return movies
17+
18+
19+
def get_imd_summary(url):
20+
movie_page = requests.get(url)
21+
soup = BeautifulSoup(movie_page.text, 'html.parser')
22+
return soup.find("div", class_="summary_text").contents[0].strip()
23+
24+
25+
def get_imd_movie_info(movie):
26+
movie_title = movie.a.contents[0]
27+
movie_year = movie.span.contents[0]
28+
movie_url = 'http://www.imdb.com' + movie.a['href']
29+
return movie_title, movie_year, movie_url
30+
31+
32+
def imd_movie_picker():
33+
ctr = 0
34+
print("================================================")
35+
for movie in get_imd_movies('http://www.imdb.com/chart/top'):
36+
movie_title, movie_year, movie_url = get_imd_movie_info(movie)
37+
movie_summary = get_imd_summary(movie_url)
38+
print(movie_title, movie_year)
39+
print(movie_summary)
40+
print("============================================")
41+
ctr = ctr+1
42+
if (ctr == 10):
43+
break
44+
45+
46+
if __name__ == '__main__':
47+
imd_movie_picker()

Day17/q59.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Extract Numbers from a string
2+
3+
4+
__author__ = "Mahtab Alam"
5+
6+
import re
7+
8+
9+
def numbers(str):
10+
return re.findall('\d+', str)
11+
12+
13+
s = "Python123"
14+
num = numbers(s)
15+
print(''.join(num))

Day17/q60.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Python program to print
2+
# even length words in a string
3+
4+
def printWords(s):
5+
s = s.split(' ')
6+
7+
for word in s:
8+
if len(word)%2==0:
9+
print(word)
10+
11+
12+
s = "This is a python language"
13+
printWords(s)

0 commit comments

Comments
 (0)