Cache FAAPI instance in scraper example
This commit is contained in:
parent
4b72b7c593
commit
421d87ffe2
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user