mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 22:31:41 +00:00
e3706f01bf
- tonutils 2.0.0: TonapiClient → ToncenterV3Client, wallet.transfer() - classes → plain async functions across all utils and methods - core/: constants.py, cookies.py, exceptions.py extracted - DEVICE constant in constants.py (single source of truth) - account/device serialised with json.dumps() in all tx payloads - tests: unittest → pytest, conftest.py fixtures, 001/002 naming - pyproject.toml: pytest + ruff config - min balance check: 0.056 TON
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import logging
|
|
import re
|
|
from typing import Any
|
|
|
|
import httpx
|
|
|
|
from app.core.exceptions import HashFetchError
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def get_fragment_hash(
|
|
cookies: dict[str, Any],
|
|
headers: dict[str, str],
|
|
page_url: str,
|
|
) -> str:
|
|
page_headers = {
|
|
**headers,
|
|
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
"referer": "https://fragment.com/",
|
|
}
|
|
|
|
async with httpx.AsyncClient(cookies=cookies) as client:
|
|
response = await client.get(page_url, headers=page_headers)
|
|
|
|
if response.status_code != 200:
|
|
raise HashFetchError(
|
|
f"Fragment returned HTTP {response.status_code} for {page_url}. "
|
|
"Check that your cookies are valid and not expired."
|
|
)
|
|
|
|
match = re.search(r"(?:https://fragment\.com)?/api\?hash=([a-f0-9]+)", response.text)
|
|
if not match:
|
|
raise HashFetchError(
|
|
f"Fragment hash not found in the page source of {page_url}. "
|
|
"The page structure may have changed or you are not logged in."
|
|
)
|
|
|
|
return match.group(1)
|