feat: add anonymous number management methods; implement get_login_code, toggle_login_codes, and terminate_sessions with associated results and error handling

This commit is contained in:
bohd4nx
2026-03-21 17:43:58 +02:00
parent ab8d463d54
commit 6e4d4da740
13 changed files with 521 additions and 6 deletions
+2
View File
@@ -1,4 +1,5 @@
from pyfragment.utils.decoder import clean_decode
from pyfragment.utils.html import parse_login_code
from pyfragment.utils.http import (
execute_transaction_request,
fragment_request,
@@ -10,6 +11,7 @@ from pyfragment.utils.wallet import get_account_info, process_transaction
__all__ = [
"clean_decode",
"parse_login_code",
"execute_transaction_request",
"fragment_request",
"get_account_info",
+23
View File
@@ -0,0 +1,23 @@
import re
# Matches the login code inside a table-cell-value element.
CODE_RE = re.compile(r'class="[^"]*table-cell-value[^"]*"[^>]*>([^<]+)<')
# Counts active session rows in the HTML table.
ROW_RE = re.compile(r"<tr[\s>]")
def parse_login_code(html: str) -> tuple[str | None, int]:
"""Extract the pending login code and active session count from a Fragment numbers page HTML snippet.
Args:
html: Raw HTML string returned by the Fragment API.
Returns:
A tuple of ``(code, active_sessions)`` where ``code`` is ``None`` if no
pending code is present, and ``active_sessions`` is the number of ``<tr>``
rows found (each row represents one active session).
"""
match = CODE_RE.search(html)
code = match.group(1).strip() if match else None
active_sessions = len(ROW_RE.findall(html))
return code, active_sessions