🎨 Use request instead of session (#363)

This commit is contained in:
Nikhil Badyal
2023-09-02 17:12:11 +05:30
committed by GitHub
parent 5c62a1b677
commit 720bfe9a3c
4 changed files with 8 additions and 9 deletions
+1 -4
View File
@@ -3,7 +3,6 @@ from pathlib import Path
from typing import List, Self from typing import List, Self
from environs import Env from environs import Env
from requests import Session
default_cli = "https://github.com/revanced/revanced-cli/releases/latest" default_cli = "https://github.com/revanced/revanced-cli/releases/latest"
default_patches = "https://github.com/revanced/revanced-patches/releases/latest" default_patches = "https://github.com/revanced/revanced-patches/releases/latest"
@@ -18,7 +17,6 @@ class RevancedConfig(object):
self.env = env self.env = env
self.temp_folder_name = "apks" self.temp_folder_name = "apks"
self.temp_folder = Path(self.temp_folder_name) self.temp_folder = Path(self.temp_folder_name)
self.session = Session()
self.ci_test = env.bool("CI_TEST", False) self.ci_test = env.bool("CI_TEST", False)
self.rip_libs_apps: List[str] = [] self.rip_libs_apps: List[str] = []
self.existing_downloaded_apks = env.list("EXISTING_DOWNLOADED_APKS", []) self.existing_downloaded_apks = env.list("EXISTING_DOWNLOADED_APKS", [])
@@ -37,10 +35,9 @@ class RevancedConfig(object):
def _fetch_or_default(self: Self, env: Env) -> None: def _fetch_or_default(self: Self, env: Env) -> None:
"""Get config from env or use default.""" """Get config from env or use default."""
from src.utils import default_build, request_header from src.utils import default_build
self.apps = env.list( self.apps = env.list(
"PATCH_APPS", "PATCH_APPS",
default_build, default_build,
) )
self.session.headers["User-Agent"] = request_header["User-Agent"]
+2 -2
View File
@@ -13,7 +13,7 @@ from src.app import APP
from src.config import RevancedConfig from src.config import RevancedConfig
from src.downloader.utils import implement_method from src.downloader.utils import implement_method
from src.exceptions import DownloadError from src.exceptions import DownloadError
from src.utils import handle_request_response from src.utils import handle_request_response, session
class Downloader(object): class Downloader(object):
@@ -39,7 +39,7 @@ class Downloader(object):
if self.config.personal_access_token and "github" in url: if self.config.personal_access_token and "github" in url:
logger.debug("Using personal access token") logger.debug("Using personal access token")
headers["Authorization"] = f"token {self.config.personal_access_token}" headers["Authorization"] = f"token {self.config.personal_access_token}"
response = self.config.session.get( response = session.get(
url, url,
stream=True, stream=True,
headers=headers, headers=headers,
+2 -2
View File
@@ -8,7 +8,7 @@ from loguru import logger
from src.app import APP from src.app import APP
from src.downloader.download import Downloader from src.downloader.download import Downloader
from src.exceptions import UptoDownAPKDownloadError from src.exceptions import UptoDownAPKDownloadError
from src.utils import bs4_parser, handle_request_response, request_header, request_timeout from src.utils import bs4_parser, handle_request_response, request_header, request_timeout, session
class UptoDown(Downloader): class UptoDown(Downloader):
@@ -43,7 +43,7 @@ class UptoDown(Downloader):
""" """
logger.debug("downloading specified version of app from uptodown.") logger.debug("downloading specified version of app from uptodown.")
url = f"{app.download_source}/versions" url = f"{app.download_source}/versions"
html = self.config.session.get(url).text html = session.get(url).text
soup = BeautifulSoup(html, bs4_parser) soup = BeautifulSoup(html, bs4_parser)
versions_list = soup.find("section", {"id": "versions"}) versions_list = soup.find("section", {"id": "versions"})
download_url = None download_url = None
+3 -1
View File
@@ -8,7 +8,7 @@ from typing import Any, Dict, List
import requests import requests
from loguru import logger from loguru import logger
from requests import Response from requests import Response, Session
from src.config import RevancedConfig from src.config import RevancedConfig
from src.downloader.sources import APK_MIRROR_APK_CHECK from src.downloader.sources import APK_MIRROR_APK_CHECK
@@ -30,6 +30,8 @@ request_header = {
bs4_parser = "html.parser" bs4_parser = "html.parser"
changelog_file = "changelog.md" changelog_file = "changelog.md"
request_timeout = 60 request_timeout = 60
session = Session()
session.headers["User-Agent"] = request_header["User-Agent"]
def update_changelog(name: str, response: Dict[str, str]) -> None: def update_changelog(name: str, response: Dict[str, str]) -> None: