File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+ else :
25+ keep_going = False
26+
27+
28+ if __name__ == '__main__' :
29+ main ()
You can’t perform that action at this time.
0 commit comments