From aecf52a095099889f1a70df3bae3796d54caf319 Mon Sep 17 00:00:00 2001 From: lomion Date: Wed, 22 Sep 2021 09:54:27 +0200 Subject: [PATCH] Renamed aiphttp_tester.py to aiohttp_tester.py Fixes flake --- aiphttp_tester.py => aiohttp_tester.py | 4 +++- drone.yaml | 2 +- requirements.txt | 2 +- tmdb/tmdb_api.py | 13 ++++++------- 4 files changed, 11 insertions(+), 10 deletions(-) rename aiphttp_tester.py => aiohttp_tester.py (87%) diff --git a/aiphttp_tester.py b/aiohttp_tester.py similarity index 87% rename from aiphttp_tester.py rename to aiohttp_tester.py index bad9709..f4b27ec 100644 --- a/aiphttp_tester.py +++ b/aiohttp_tester.py @@ -2,12 +2,14 @@ from tmdb.tmdb_api import Movie import asyncio import time + async def test(): start = time.time() movie = Movie() await movie.load_parameters() id = await movie.search_title('Breakfast Club') + print("ID of Breakfast Club " + id) print(time.time() - start) await movie.close_session() - + asyncio.run(test()) diff --git a/drone.yaml b/drone.yaml index f1bbe41..7dc64fd 100644 --- a/drone.yaml +++ b/drone.yaml @@ -5,7 +5,7 @@ pipeline: - pip install -r requirements.txt - pip install flake8 - python3 test_tmdb.py - - flake8 --ignore=E501 --exclude=__init__.py + - flake8 --ignore=E501 --exclude=__init__.py --exclude=test_tmdb.py build: image: alpine diff --git a/requirements.txt b/requirements.txt index e9210a3..6e56275 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ maubot -requests \ No newline at end of file +aiohttp \ No newline at end of file diff --git a/tmdb/tmdb_api.py b/tmdb/tmdb_api.py index 8edc35c..90612bd 100644 --- a/tmdb/tmdb_api.py +++ b/tmdb/tmdb_api.py @@ -13,9 +13,9 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with tmdb-bot. If not, see . ''' -import requests from html import escape -import aiohttp, asyncio +import aiohttp +import asyncio class TmdbApi(): @@ -65,9 +65,9 @@ class TmdbApiSingle(TmdbApi): def get_image_binary(self): if self.poster_url: - return requests.get(self.poster_url).content - else: - return None + async with self.session.get(self.poster_url) as resp: + return await resp.json() + return None def set_poster_size(self, size): for x in self.poster_sizes: @@ -126,8 +126,7 @@ class Movie(TmdbApiSingle): movie_id = json['results'][0]['id'] await asyncio.gather( self.query_details(movie_id), - self.query_cast(movie_id) - ) + self.query_cast(movie_id)) return movie_id async def query_details(self, id):