shared -> http_pool

This commit is contained in:
DarkCat09 2024-04-28 14:06:20 +04:00
parent 80a7d2bde5
commit ab93124337
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3
2 changed files with 5 additions and 4 deletions

View file

@ -2,7 +2,7 @@ import re
from lxml import html, etree # type: ignore from lxml import html, etree # type: ignore
import shared import http_pool
# Matches not only latin symbols, # Matches not only latin symbols,
@ -20,7 +20,7 @@ def search(title: str, artist: str) -> str:
'''Searches for Genius lyrics using SearXNG + Yahoo and returns the first URL. '''Searches for Genius lyrics using SearXNG + Yahoo and returns the first URL.
Irrelevant texts should be picked manually''' Irrelevant texts should be picked manually'''
resp = shared.get_http_pool().request( resp = http_pool.get().request(
'GET', 'GET',
'https://searx.dc09.ru/search', 'https://searx.dc09.ru/search',
fields={ fields={
@ -41,7 +41,7 @@ def parse(url: str) -> str:
'''Requests a lyrics page and parses with libxml2, '''Requests a lyrics page and parses with libxml2,
leaving only text and line breaks''' leaving only text and line breaks'''
resp = shared.get_http_pool().request('GET', url) resp = http_pool.get().request('GET', url)
tree = html.document_fromstring(resp.data) tree = html.document_fromstring(resp.data)
divs = lyrics_xpath(tree) divs = lyrics_xpath(tree)
del resp, tree del resp, tree

View file

@ -3,7 +3,8 @@ from urllib3 import PoolManager
_http: PoolManager | None = None _http: PoolManager | None = None
def get_http_pool() -> PoolManager:
def get() -> PoolManager:
global _http global _http
if _http is None: if _http is None:
_http = PoolManager() _http = PoolManager()