From ab931243378bdab9b41794989df7b412d3e9b085 Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Sun, 28 Apr 2024 14:06:20 +0400 Subject: [PATCH] shared -> http_pool --- backend/genius.py | 6 +++--- backend/{shared.py => http_pool.py} | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) rename backend/{shared.py => http_pool.py} (81%) diff --git a/backend/genius.py b/backend/genius.py index de70b89..013a55f 100644 --- a/backend/genius.py +++ b/backend/genius.py @@ -2,7 +2,7 @@ import re from lxml import html, etree # type: ignore -import shared +import http_pool # 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. Irrelevant texts should be picked manually''' - resp = shared.get_http_pool().request( + resp = http_pool.get().request( 'GET', 'https://searx.dc09.ru/search', fields={ @@ -41,7 +41,7 @@ def parse(url: str) -> str: '''Requests a lyrics page and parses with libxml2, 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) divs = lyrics_xpath(tree) del resp, tree diff --git a/backend/shared.py b/backend/http_pool.py similarity index 81% rename from backend/shared.py rename to backend/http_pool.py index ccc0447..9e649ee 100644 --- a/backend/shared.py +++ b/backend/http_pool.py @@ -3,7 +3,8 @@ from urllib3 import PoolManager _http: PoolManager | None = None -def get_http_pool() -> PoolManager: + +def get() -> PoolManager: global _http if _http is None: _http = PoolManager()