maxapi-python 1.2.3__py3-none-any.whl → 1.2.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {maxapi_python-1.2.3.dist-info → maxapi_python-1.2.4.dist-info}/METADATA +12 -7
- maxapi_python-1.2.4.dist-info/RECORD +33 -0
- pymax/core.py +54 -37
- pymax/files.py +28 -7
- pymax/interfaces.py +410 -115
- pymax/mixins/auth.py +2 -2
- pymax/mixins/channel.py +3 -5
- pymax/mixins/group.py +2 -2
- pymax/mixins/handler.py +4 -10
- pymax/mixins/message.py +64 -88
- pymax/mixins/scheduler.py +1 -1
- pymax/mixins/self.py +2 -2
- pymax/mixins/socket.py +3 -336
- pymax/mixins/telemetry.py +2 -4
- pymax/mixins/user.py +3 -5
- pymax/mixins/websocket.py +5 -363
- pymax/payloads.py +8 -1
- pymax/protocols.py +123 -0
- pymax/static/constant.py +69 -8
- pymax/static/enum.py +5 -0
- pymax/types.py +25 -0
- pymax/utils.py +90 -0
- maxapi_python-1.2.3.dist-info/RECORD +0 -32
- pymax/mixins/utils.py +0 -27
- {maxapi_python-1.2.3.dist-info → maxapi_python-1.2.4.dist-info}/WHEEL +0 -0
- {maxapi_python-1.2.3.dist-info → maxapi_python-1.2.4.dist-info}/licenses/LICENSE +0 -0
pymax/utils.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import time
|
|
3
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
4
|
+
from typing import Any, NoReturn
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
from pymax.exceptions import Error, RateLimitError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MixinsUtils:
|
|
12
|
+
@staticmethod
|
|
13
|
+
def handle_error(data: dict[str, Any]) -> NoReturn:
|
|
14
|
+
error = data.get("payload", {}).get("error")
|
|
15
|
+
localized_message = data.get("payload", {}).get("localizedMessage")
|
|
16
|
+
title = data.get("payload", {}).get("title")
|
|
17
|
+
message = data.get("payload", {}).get("message")
|
|
18
|
+
|
|
19
|
+
if error == "too.many.requests": # TODO: вынести в статик
|
|
20
|
+
raise RateLimitError(
|
|
21
|
+
error=error,
|
|
22
|
+
message=message,
|
|
23
|
+
title=title,
|
|
24
|
+
localized_message=localized_message,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
raise Error(
|
|
28
|
+
error=error,
|
|
29
|
+
message=message,
|
|
30
|
+
title=title,
|
|
31
|
+
localized_message=localized_message,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def _fetch_and_extract(url: str, session: requests.Session) -> str | None:
|
|
36
|
+
try:
|
|
37
|
+
js_code = session.get(url, timeout=10).text
|
|
38
|
+
except requests.RequestException:
|
|
39
|
+
return None
|
|
40
|
+
return MixinsUtils._extract_version(js_code)
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def _extract_version(js_code: str) -> str | None:
|
|
44
|
+
ws_anchor = "wss://ws-api.oneme.ru/websocket"
|
|
45
|
+
pos = js_code.find(ws_anchor)
|
|
46
|
+
if pos == -1:
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
snippet = js_code[pos : pos + 2000]
|
|
50
|
+
|
|
51
|
+
match = re.search(r'[:=]\s*"(\d{1,2}\.\d{1,2}\.\d{1,2})"', snippet)
|
|
52
|
+
if match:
|
|
53
|
+
version = match.group(1)
|
|
54
|
+
return version
|
|
55
|
+
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
@staticmethod
|
|
59
|
+
def get_current_web_version() -> str | None:
|
|
60
|
+
try:
|
|
61
|
+
html = requests.get("https://web.max.ru/", timeout=10).text
|
|
62
|
+
except requests.RequestException:
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
main_chunk_import = html.split("import(")[2].split(")")[0].strip("\"'")
|
|
66
|
+
main_chunk_url = f"https://web.max.ru{main_chunk_import}"
|
|
67
|
+
try:
|
|
68
|
+
main_chunk_code = requests.get(main_chunk_url, timeout=10).text
|
|
69
|
+
except requests.exceptions.RequestException as e:
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
arr = main_chunk_code.split("\n")[0].split("[")[1].split("]")[0].split(",")
|
|
73
|
+
urls = []
|
|
74
|
+
for i in arr:
|
|
75
|
+
if "/chunks/" in i:
|
|
76
|
+
url = "https://web.max.ru/_app/immutable" + i[3 : len(i) - 1]
|
|
77
|
+
urls.append(url)
|
|
78
|
+
|
|
79
|
+
session = requests.Session()
|
|
80
|
+
session.headers["User-Agent"] = "Mozilla/5.0"
|
|
81
|
+
if urls:
|
|
82
|
+
with ThreadPoolExecutor(max_workers=8) as pool:
|
|
83
|
+
futures = [
|
|
84
|
+
pool.submit(MixinsUtils._fetch_and_extract, url, session) for url in urls
|
|
85
|
+
]
|
|
86
|
+
for f in as_completed(futures):
|
|
87
|
+
ver = f.result()
|
|
88
|
+
if ver:
|
|
89
|
+
return ver
|
|
90
|
+
return None
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
pymax/__init__.py,sha256=6wUKKwsyxFpWG3b7kwptOvHd-w78C-ygw42iCDBYQvc,1915
|
|
2
|
-
pymax/core.py,sha256=S5el07cMcqIyXOI25G0a2XtVJSz2_AltmKN7ZW6LEeg,14946
|
|
3
|
-
pymax/crud.py,sha256=YC92TyhA2mr1tJCcfd-tvh8umtXKgqJfgiLo7nXUl3Q,3076
|
|
4
|
-
pymax/exceptions.py,sha256=nDUNx7bM-Yjugj-qfIllcrnwLg9JpZroYqfXapjYbMQ,3178
|
|
5
|
-
pymax/files.py,sha256=bSjP1m-dLPJCN8HPZtjrLLp0Oc7OxdGxI6U1K2rQzUA,3587
|
|
6
|
-
pymax/filters.py,sha256=gSHPJ1Vi37HKPxf0jRRv9Q3iGwhiQjw1MGrCaouqHzs,4325
|
|
7
|
-
pymax/formatter.py,sha256=RJ_5VbY7Li8UM3xL1AvcXo8v1iYnY8GvDDkreaFqtnY,860
|
|
8
|
-
pymax/formatting.py,sha256=XRtuXJGweuNZevJFdPxksDftIrfuMGEA-AOUc_v6IhQ,2484
|
|
9
|
-
pymax/interfaces.py,sha256=5-0RM0tH3eBJrVZkjL494lKTTwvIVmOTJiQxDWZo-7A,8829
|
|
10
|
-
pymax/models.py,sha256=PsPGbOkERxesZZltjNrmqhOfRcO44Is2ThbEToREcB8,201
|
|
11
|
-
pymax/navigation.py,sha256=4ia6RGY2pXMArboNhHkbWlWX7LtcYK1VGVXorPX0Pb4,5747
|
|
12
|
-
pymax/payloads.py,sha256=tlqPT-JFexfklp9idSrbpU3bALcQuiDne9H9vTnwL4w,8022
|
|
13
|
-
pymax/types.py,sha256=_Ee1aycVwe4nfBO_hGMnpm9lQDGzkPOkT9vME8OL-sA,36650
|
|
14
|
-
pymax/mixins/__init__.py,sha256=5sXJME34S1EssuDETaN4DLRH7vhMw_Q3Jmay9myAIZM,775
|
|
15
|
-
pymax/mixins/auth.py,sha256=e90vIpEOwAjUxgYMYaG7R6jR_5t9rKsei_mTBQUirL4,14716
|
|
16
|
-
pymax/mixins/channel.py,sha256=W52YnBay1sUYXxF9oAWsz44ZUh_s45jSvKmAyjTbULM,5357
|
|
17
|
-
pymax/mixins/group.py,sha256=MaiZCQ9R-wWbuEPXyqf4JZAGNmxu_tXCs8qU3JEoYek,15911
|
|
18
|
-
pymax/mixins/handler.py,sha256=ETnI8fA386LYJGjWtUhhWzQHREUA78di1aO1oWwtscA,12523
|
|
19
|
-
pymax/mixins/message.py,sha256=AznKKmTMxdzsYl8IecT43RjWpGvlQM85GzSNGFbI8BA,33279
|
|
20
|
-
pymax/mixins/scheduler.py,sha256=rcMfgfZnzu5V6MkcCg6uRgbi-jkc7UyqOjemulydWbc,964
|
|
21
|
-
pymax/mixins/self.py,sha256=27ranVw5rdv1qSplhV5mdUvHc4qSxHi63f1gWOjR9B4,9182
|
|
22
|
-
pymax/mixins/socket.py,sha256=tk2puQPsT2Dltg1j6kUSHIbXs64p6q-jiIIcs73Y1Sk,23174
|
|
23
|
-
pymax/mixins/telemetry.py,sha256=LWr68DNQkPhAjGRDYQ5lORXxC3Yw6M9E8sF0TCNISTE,3609
|
|
24
|
-
pymax/mixins/user.py,sha256=RSZd4t-aq8P2k3cVzNVWBkUf-_xTWILrBzwxLRgk1pw,9450
|
|
25
|
-
pymax/mixins/utils.py,sha256=s3FUf3i_wjn2Gbg5YY1rWZB-90ZEGrrcUuND_MqqSTE,853
|
|
26
|
-
pymax/mixins/websocket.py,sha256=fL8IcsLkvksizSAg98UaFlDPZGyGbYtbtdHnlDzfR9g,18056
|
|
27
|
-
pymax/static/constant.py,sha256=nM0svv3VpsVxK-RqoADn9qsTdQvB-IYv0Sgv-bQcWs4,1116
|
|
28
|
-
pymax/static/enum.py,sha256=mraN6FK_gcVXdTHBdK8Zf6-92AzVFGAWRnQLA4rzYBA,4672
|
|
29
|
-
maxapi_python-1.2.3.dist-info/METADATA,sha256=0NSb43LEMf9-M1KLeETofzdcjsGJ68lpZ15xP9GouI0,6753
|
|
30
|
-
maxapi_python-1.2.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
31
|
-
maxapi_python-1.2.3.dist-info/licenses/LICENSE,sha256=hOR249ItqMdcly1A0amqEWRNRTq4Gv5NJtmQ3A5qK4E,1070
|
|
32
|
-
maxapi_python-1.2.3.dist-info/RECORD,,
|
pymax/mixins/utils.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
from typing import Any, NoReturn
|
|
2
|
-
|
|
3
|
-
from pymax.exceptions import Error, RateLimitError
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class MixinsUtils:
|
|
7
|
-
@staticmethod
|
|
8
|
-
def handle_error(data: dict[str, Any]) -> NoReturn:
|
|
9
|
-
error = data.get("payload", {}).get("error")
|
|
10
|
-
localized_message = data.get("payload", {}).get("localizedMessage")
|
|
11
|
-
title = data.get("payload", {}).get("title")
|
|
12
|
-
message = data.get("payload", {}).get("message")
|
|
13
|
-
|
|
14
|
-
if error == "too.many.requests": # TODO: вынести в статик
|
|
15
|
-
raise RateLimitError(
|
|
16
|
-
error=error,
|
|
17
|
-
message=message,
|
|
18
|
-
title=title,
|
|
19
|
-
localized_message=localized_message,
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
raise Error(
|
|
23
|
-
error=error,
|
|
24
|
-
message=message,
|
|
25
|
-
title=title,
|
|
26
|
-
localized_message=localized_message,
|
|
27
|
-
)
|
|
File without changes
|
|
File without changes
|