From 421d87ffe2b05674cce5dc61a00c16df05e761de Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Thu, 3 Dec 2020 23:59:59 +1030 Subject: [PATCH] Cache FAAPI instance in scraper example --- FAAPI/FaveScraper.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/FAAPI/FaveScraper.py b/FAAPI/FaveScraper.py index 9f6fd97..a3e2fa1 100755 --- a/FAAPI/FaveScraper.py +++ b/FAAPI/FaveScraper.py @@ -3,6 +3,7 @@ import multiprocessing import requests +import shelve from FAAPI import FAAPI @@ -20,11 +21,20 @@ def download(url: str): if __name__ == '__main__': # Get an API instance - api = FAAPI() + shelf = shelve.open('api.shelf') + try: + api = shelf['api'] if 'api' in shelf.keys() else FAAPI() + except: + api = FAAPI() + shelf['api'] = api # Log in api.login() + # Save the API + shelf['api'] = api + shelf.close() + # Get the user we've authenticated as user = api.get_user(api.username) if not user: