We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dc43586 commit 313bfd2Copy full SHA for 313bfd2
1 file changed
experiments/movie.py
@@ -0,0 +1,29 @@
1
+import json
2
+import requests
3
+
4
5
+def do_search(search_term):
6
+ req = requests.get('http://www.omdbapi.com/', params={'s': search_term, 'type': 'movie'})
7
+ if req.status_code == requests.codes.ok:
8
+ movies = json.loads(req.text) # not using req.json in order to sort
9
+ if 'Search' in movies:
10
+ lines = sorted(movies['Search'], key=lambda m: m['Year'], reverse=True)
11
12
+ for movie in lines:
13
+ print("{} - {}".format(movie['Year'], movie['Title']))
14
+ else:
15
+ print('Nothing found')
16
17
18
+def main():
19
+ keep_going = True
20
+ while keep_going:
21
+ search = input('Search for a movie [enter to stop]: ')
22
+ if search.strip():
23
+ do_search(search)
24
25
+ keep_going = False
26
27
28
+if __name__ == '__main__':
29
+ main()
0 commit comments