Refactoring to eliminate models. Moved to SQLAlchemy Mapped annotations

This commit is contained in:
Ettore
2026-05-06 23:51:29 +02:00
parent e153d54917
commit d30b320595
9 changed files with 70 additions and 117 deletions

View File

@@ -1,18 +1,18 @@
import requests
from fake_useragent import UserAgent
from models import Credential
class AVConnectAPI:
_BASE_URL = "https://www.avconnect.it"
def __init__(self, credentials: Credential):
def __init__(self, username: str, password: str, session_id: str | None = None):
self._ua = UserAgent(browsers=["Chrome Mobile"], os=["Android"], platforms=["mobile"]).random
self._credentials = credentials
self._username = username
self._password = password
self._session = requests.Session()
self._authenticated = False
if credentials.sessionid:
self._session.cookies.set("PHPSESSID", credentials.sessionid)
if session_id:
self._session.cookies.set("PHPSESSID", session_id)
self._authenticated = True
def _authenticate(self) -> bool:
@@ -21,7 +21,7 @@ class AVConnectAPI:
"User-Agent": self._ua,
"Content-Type": "application/x-www-form-urlencoded"
}
payload = f"userid={self._credentials.username}&password={self._credentials.password}&entra=Login"
payload = f"userid={self._username}&password={self._password}&entra=Login"
response = self._session.post(login_url, data=payload, headers=headers)
if response.ok and "PHPSESSID" in self._session.cookies:
self._authenticated = True
@@ -30,7 +30,7 @@ class AVConnectAPI:
return False
def _check_sessionid(self) -> bool:
if not self._authenticated or not self._credentials.sessionid:
if not self._authenticated or not self._session.cookies.get("PHPSESSID"):
return False
exec_url = f"{self._BASE_URL}/exemacrocom.php"
headers = {