Skip to content

Commit

Permalink
fix(gsm_arena): use new private CORS Bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
HitaloM committed Sep 30, 2024
1 parent d44a2b0 commit 6615181
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: check-yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.5
rev: v0.6.8
hooks:
- id: ruff-format
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = ["pre-commit>=3.8.0", "ruff>=0.6.5"]
dev-dependencies = ["pre-commit>=3.8.0", "ruff>=0.6.8"]

[project.optional-dependencies]
docs = [
Expand Down
1 change: 1 addition & 0 deletions src/korone/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"SENTRY_DSN": "",
"DEEPL_KEY": "",
"LASTFM_KEY": "",
"CORS_BYPASS": "",
},
}

Expand Down
5 changes: 4 additions & 1 deletion src/korone/modules/gsm_arena/utils/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import httpx
from lxml import html

from korone.config import ConfigManager
from korone.utils.caching import cache
from korone.utils.i18n import gettext as _
from korone.utils.logging import logger

from .types import PhoneSearchResult

CORS: str = ConfigManager.get("korone", "CORS_BYPASS")

HEADERS = {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,"
"image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
Expand Down Expand Up @@ -105,7 +108,7 @@ def format_phone(phone: dict[str, Any]) -> str:
async def fetch_html(url: str) -> str:
try:
async with httpx.AsyncClient(headers=HEADERS, http2=True) as session:
response = await session.get(f"https://cors-bypass.amano.workers.dev/{url}")
response = await session.get(f"{CORS}/{url}")
response.raise_for_status()
return response.text
except httpx.HTTPStatusError as e:
Expand Down

0 comments on commit 6615181

Please sign in to comment.