Use requests.Session to greatly speed up RSS requests.

This commit is contained in:
voussoir 2020-11-09 16:30:25 -08:00
parent 1263123a03
commit a3f69573a4

View file

@ -5,11 +5,12 @@ import requests
from . import exceptions from . import exceptions
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
session = requests.Session()
def _get_user_videos(uid): def _get_user_videos(uid):
log.debug(f'Fetching RSS for {uid}.') log.debug(f'Fetching RSS for {uid}.')
url = f'https://www.youtube.com/feeds/videos.xml?channel_id={uid}' url = f'https://www.youtube.com/feeds/videos.xml?channel_id={uid}'
response = requests.get(url) response = session.get(url)
response.raise_for_status() response.raise_for_status()
soup = bs4.BeautifulSoup(response.text, 'lxml') soup = bs4.BeautifulSoup(response.text, 'lxml')
# find_all does not work on namespaced tags unless you add a limit paramter. # find_all does not work on namespaced tags unless you add a limit paramter.