Complete refactor... Some issue...

This commit is contained in:
2025-05-11 02:09:24 +02:00
parent c763e76ec7
commit ebd8529c41
8 changed files with 431 additions and 179 deletions

View File

@@ -1,42 +1,46 @@
import requests
import pprint
BASE_URL = "https://www.avconnect.it"
from fake_useragent import UserAgent
from commons import Credential
class AVConnectAPI:
def __init__(self, username: str, password: str):
self.username = username
self.password = password
self.session = requests.Session()
self.authenticated = False
_BASE_URL = "https://www.avconnect.it"
def authenticate(self) -> bool:
login_url = f"{BASE_URL}/loginone.php"
def __init__(self, credentials: Credential):
self._ua = UserAgent(browsers=["Chrome Mobile"], os=["Android"], platforms=["mobile"]).random
self._username = credentials.username
self._password = credentials.password
self._session = requests.Session()
self._authenticated = False
def _authenticate(self) -> bool:
login_url = f"{self._BASE_URL}/loginone.php"
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
payload = f"userid={self.username}&password={self.password}&entra=Login"
response = self.session.post(login_url, data=payload, headers=headers)
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
if response.ok and "PHPSESSID" in self._session.cookies:
self._authenticated = True
return True
return False
def exec_gate_macro(self, id_macro) -> requests.Response:
if not self.authenticated and not self.authenticate():
def exec_gate_macro(self, id_macro) -> bool:
if not self._authenticated and not self._authenticate():
raise Exception("Authentication failed.")
exec_url = f"{BASE_URL}/exemacrocom.php"
exec_url = f"{self._BASE_URL}/exemacrocom.php"
headers = {
"User-Agent": self._ua,
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
payload = f"idmacrocom={id_macro}&nome=16"
response = self.session.prepare_request(requests.Request("POST", exec_url, data=payload, headers=headers))
response = self._session.prepare_request(requests.Request("POST", exec_url, data=payload, headers=headers))
pprint.pprint(response.headers)
return True
#response = self.session.post(exec_url, data=payload, headers=headers)
#response = self._session.post(exec_url, data=payload, headers=headers)
#if response.ok:
# return True
#return False