Skip to content

Commit 6f3d86c

Browse files
committed
play around version done and pythonic.
1 parent 1733fec commit 6f3d86c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

apps/10_movie_search/final/play.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import requests
2+
import collections
3+
4+
MovieResult = collections.namedtuple(
5+
'MovieResult',
6+
"imdb_code,title,duration,director,year,rating,imdb_score,keywords,genres")
7+
8+
search = input("What movie do you want to search for? ")
9+
url = 'http://movie_service.talkpython.fm/api/search/{}'.format(search)
10+
11+
resp = requests.get(url)
12+
resp.raise_for_status()
13+
14+
movie_data = resp.json()
15+
movies_list = movie_data.get('hits')
16+
17+
# movies = []
18+
# for md in movies_list:
19+
# m = MovieResult(
20+
# imdb_code=md.get('imdb_code'),
21+
# title=md.get('title'),
22+
# duration=md.get('duration'),
23+
# director=md.get('director'),
24+
# year=md.get('year', 0),
25+
# rating=md.get('rating', 0),
26+
# imdb_score=md.get('imdb_score', 0.0),
27+
# keywords=md.get('keywords'),
28+
# genres=md.get('genres')
29+
# )
30+
# movies.append(m)
31+
32+
# def method(x, y, z, **kwargs):
33+
# print("kwargs=", kwargs)
34+
#
35+
# method(7, 1, z=2, format=True, age=7)
36+
37+
# movies = []
38+
# for md in movies_list:
39+
# m = MovieResult(**md)
40+
# movies.append(m)
41+
42+
movies = [
43+
MovieResult(**md)
44+
for md in movies_list
45+
]
46+
47+
print("Found {} movies for search {}".format(len(movies), search))
48+
for m in movies:
49+
print("{} -- {}".format(m.year, m.title))

0 commit comments

Comments
 (0)