From 042f732c6985e4289d8f3ebb925f030ae340eb5a Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Wed, 22 Apr 2020 04:52:00 +0930 Subject: [PATCH] Cache preview URLs early Totally not modifying the API to conform with the project based on it --- FAAPI/FAAPI.py | 16 ++++++++++++++++ setup.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/FAAPI/FAAPI.py b/FAAPI/FAAPI.py index c940ce1..8cf7f29 100644 --- a/FAAPI/FAAPI.py +++ b/FAAPI/FAAPI.py @@ -339,6 +339,14 @@ class User: # Get all the submissions on this page for item in soup.select('.gallery figure'): sub = Submission.new_or_cached(self._api, int(item.get('id')[4:])) # IDs look like 'sid-35908275', so we just skip the 'sid-' + + # Try cache the preview URL early + try: + sub._preview_url = 'https:' + item.select('img')[0].get('src') + sub._has_preview = True + except IndexError: + sub._has_preview = False + submissions.append(sub) return submissions @@ -360,6 +368,14 @@ class User: # Get all the submissions on this page for item in soup.select('.gallery figure'): sub = Submission.new_or_cached(self._api, int(item.get('id')[4:])) # IDs look like 'sid-35908275', so we just skip the 'sid-' + + # Try cache the preview URL early + try: + sub._preview_url = 'https:' + item.select('img')[0].get('src') + sub._has_preview = True + except IndexError: + sub._has_preview = False + submissions.append(sub) return submissions diff --git a/setup.py b/setup.py index ea34de8..7422050 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='FAAPI', - version='0.4.0', + version='0.4.2', packages=find_packages(), url='https://tem.party/gitea/tom/FAAPI', license='WTFPL',