From 806593afa18bb6880d79a1773c3a6db33a8caaa7 Mon Sep 17 00:00:00 2001 From: neingeist Date: Thu, 8 Nov 2018 16:33:30 +0100 Subject: [PATCH] add rest-client-yts.py --- rest-client-yts.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 rest-client-yts.py diff --git a/rest-client-yts.py b/rest-client-yts.py new file mode 100755 index 0000000..5e965ac --- /dev/null +++ b/rest-client-yts.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# List latest good movies on YTS + +from simple_rest_client.api import API +from simple_rest_client.resource import Resource +import progressbar + + +class MovieResource(Resource): + actions = { + 'list': {'method': 'GET', 'url': 'list_movies.json'}, + } + + +def good(movie): + return movie['rating'] >= 7.5 + + +api = API(api_root_url='https://yts.am/api/v2') +api.add_resource(resource_name='movies', resource_class=MovieResource) + +max_movies = 20 +with progressbar.ProgressBar(max_value=max_movies) as bar: + page = 0 + movies = [] + while len(movies) < max_movies and page < 20: + page += 1 + movies_new = api.movies.list(params={'limit': 50, 'page': page}).body['data']['movies'] + movies_new = [movie for movie in movies_new if good(movie)] + movies += movies_new + bar.update(min(max_movies, len(movies))) + +for movie in sorted(movies, key=lambda m: m['rating'], reverse=True): + print('{rating:3.1f} {title}\n {url}'.format(**movie))