Try pooling API requests

This commit is contained in:
Jason McBrayer 2019-07-23 09:33:09 -04:00
parent 0efbc552b7
commit e1d758765d
1 changed files with 11 additions and 0 deletions

View File

@ -26,17 +26,27 @@ from urllib import parse
from pdb import set_trace
from inscriptis import get_text
from time import sleep
from requests import Session
import re
class NotLoggedInException(Exception):
pass
global sessons_cache
sessions_cache = {}
###
### Utility functions
###
def get_session(domain):
if domain in sessions_cache:
return sessions_cache[domain]
else:
s = Session()
sessions_cache[domain] = s
return s
def get_usercontext(request):
if is_logged_in(request):
@ -55,6 +65,7 @@ def get_usercontext(request):
client_secret=client.client_secret,
access_token=user.access_token,
api_base_url=client.api_base_id,
session = get_session(client.api_base_id),
ratelimit_method="throw",
)
return user, mastodon