Skip to content

Commit 2665088

Browse files
committed
Movie and TV ratings scraper - fixing lint with flake8 errors
1 parent 74200c6 commit 2665088

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

movie_tv_ratings/movie_tv_ratings.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
import requests
22
import re
3-
import sys
43
from bs4 import BeautifulSoup
54

6-
##### Gets top 250 movies from IMDB
5+
# Gets top 250 movies from IMDB
76
def scrape_movies():
7+
88
response = requests.get('http://www.imdb.com/chart/top')
99
soup = BeautifulSoup(response.text, 'lxml')
1010

1111
movies = soup.select('td.titleColumn')
12-
ratings = [b.attrs.get('data-value')
13-
for b in soup.select('td.posterColumn span[name=ir]')]
12+
ratings = [b.attrs.get('data-value') for b in soup.select('td.posterColumn span[name=ir]')]
1413

1514
for i in range(len(movies)):
1615
movie_string = movies[i].get_text()
1716
movie = (' '.join(movie_string.split()).replace('.', ''))
1817
movie_title = movie[len(str(i))+1:-7]
19-
print("| " + str(i+1) + " | " + movie_title + " | Rating : " + "{:.1f}".format(float(ratings[i])))
20-
return
18+
print(("| " + str(i+1)) + (" | " + movie_title) + (" | Rating : " + "{:.1f}".format(float(ratings[i]))))
19+
return
2120

2221

23-
##### Gets top 250 TV shows from IMDB
22+
# Gets top 250 TV shows from IMDB
2423
def scrape_tvshows():
2524
page = requests.get("https://www.imdb.com/chart/toptv")
2625
Results = re.findall(r'" alt="(.+?)".*?title="(.*?)".*?strong.*?"(.*?)"', page.text, re.DOTALL)
2726
for i in range(len(Results)):
2827
print("| " + str(i+1) + " | " + Results[i][0] + " | Rating : " + Results[i][-1][:3])
29-
30-
return
28+
29+
return
3130

3231

33-
##### USER INTERFACE #####
32+
# USER INTERFACE
3433

3534
print("Type 'Movies' to get the Top 250 Movies on IMDB\n")
3635
print("Type 'TV' to get the Top 250 TV Shows on IMDB\n")
@@ -40,17 +39,13 @@ def scrape_tvshows():
4039
while (val):
4140
if val == 'Movies':
4241
globals()['scrape_movies']()
43-
4442
print("\n")
45-
4643
val = input("Type 'Movies' or 'TV' or 'exit': ")
47-
4844
elif val == 'TV':
4945
globals()['scrape_tvshows']()
5046
print("\n")
5147
val = input("Type 'Movies' or 'TV' or 'exit': ")
52-
5348
elif val == 'exit':
5449
val = ''
5550
else:
56-
val = input("Wrong Input. Try Again: ")
51+
val = input("Wrong Input. Try Again: ")

0 commit comments

Comments
 (0)