dipx 0.1.0__tar.gz

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.
dipx-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 aue.a
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
dipx-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,104 @@
1
+ Metadata-Version: 2.4
2
+ Name: dipx
3
+ Version: 0.1.0
4
+ Summary: Python client library for dip-x.store marketplace
5
+ Project-URL: Homepage, https://github.com/FreezeRust/dipx
6
+ Project-URL: Issues, https://github.com/FreezeRust/dipx/issues
7
+ Author-email: "aue.a" <aue.a@internet.ru>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: api,dip-x,dipx,marketplace
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.9
21
+ Requires-Dist: beautifulsoup4>=4.11
22
+ Requires-Dist: requests>=2.28
23
+ Description-Content-Type: text/markdown
24
+
25
+ # dipx
26
+
27
+ Python client for the [dip-x.store](https://dip-x.store) marketplace.
28
+
29
+ ```bash
30
+ pip install dipx
31
+ ```
32
+
33
+ ```python
34
+ from dipx import DipXClient
35
+
36
+ client = DipXClient()
37
+ profile = client.login("Lincoln", "your_password")
38
+
39
+ print(profile.username) # Lincoln
40
+ print(profile.id) # 10434
41
+
42
+ bal = client.get_balance()
43
+ print(f"Total: {bal.total} ₽ (available {bal.available} ₽, frozen {bal.frozen} ₽)")
44
+
45
+ for p in client.get_my_products():
46
+ print(f"[{p.id}] {p.title} — {p.price} ₽ ({p.status})")
47
+
48
+ client.logout()
49
+ ```
50
+
51
+ See [the full method reference](#api-overview) below.
52
+
53
+ ## Features
54
+
55
+ - 🔐 login / logout / profile / change password
56
+ - 💰 balance, transactions, deposit (lolz, platega, anypay, cryptobot, ...)
57
+ - 📦 products: list / create / update / delete / hide / show / bulk-ops
58
+ - 🚀 bump: free / paid + plugin-based auto-bump
59
+ - 🛒 orders: list, refund, complaint
60
+ - 💬 chat: list conversations, get/send/load older messages, media, pin, delete
61
+ - 🚫 block / mute users + blocklist
62
+ - ❤️ wishlist: check / toggle / add / remove
63
+ - ⭐ reviews: leave / reply / list
64
+ - 🔔 notifications: get / update settings
65
+ - 🔗 integrations: Telegram / VK link & unlink
66
+ - 📊 stats: heatmap, today's earnings, dashboard
67
+
68
+ ## Exception types
69
+
70
+ ```python
71
+ from dipx import (
72
+ AuthError,
73
+ NotFoundError,
74
+ ValidationError,
75
+ InsufficientBalanceError,
76
+ RateLimitError,
77
+ DipXError,
78
+ )
79
+ ```
80
+
81
+ All exceptions carry a `status_code` (HTTP) and optional `payload` (parsed JSON
82
+ body).
83
+
84
+ ## API overview
85
+
86
+ | Group | Methods |
87
+ |-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
88
+ | Auth | `login`, `logout`, `me` |
89
+ | Profile | `get_profile`, `update_profile`, `change_password` |
90
+ | Balance | `get_balance`, `get_transactions`, `create_deposit`, `request_withdrawal` |
91
+ | Products | `get_my_products`, `get_product`, `create_product`, `update_product`, `delete_product`, `hide_product`, `show_product`, `toggle_product_visibility`, `bulk_hide_products`, `bulk_show_products` |
92
+ | Bump | `get_bump_info`, `bump_product`, `bump_all_free`, `setup_auto_bump`, `cancel_auto_bump`, `resume_auto_bump`, `buy_auto_bump_plugin` |
93
+ | Orders | `get_orders`, `get_order`, `request_refund`, `confirm_order`, `cancel_order`, `dispute_order`, `file_complaint` |
94
+ | Chat | `get_conversations`, `get_unread_count`, `get_messages`, `get_older_messages`, `send_message`, `get_media`, `pin_conversation`, `delete_conversation` |
95
+ | Block / Mute | `block_user`, `mute_user`, `get_blocked_users` |
96
+ | Wishlist | `check_wishlist`, `toggle_wishlist`, `add_to_wishlist`, `remove_from_wishlist` |
97
+ | Reviews | `leave_review`, `reply_to_review`, `delete_review_reply`, `get_user_reviews` |
98
+ | Notifications | `get_notification_settings`, `update_notification_settings` |
99
+ | Integrations | `link_telegram`, `unlink_telegram`, `unlink_vk` |
100
+ | Stats | `get_activity_heatmap`, `get_today_earnings`, `get_stats` |
101
+
102
+ ## License
103
+
104
+ MIT
dipx-0.1.0/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # dipx
2
+
3
+ Python client for the [dip-x.store](https://dip-x.store) marketplace.
4
+
5
+ ```bash
6
+ pip install dipx
7
+ ```
8
+
9
+ ```python
10
+ from dipx import DipXClient
11
+
12
+ client = DipXClient()
13
+ profile = client.login("Lincoln", "your_password")
14
+
15
+ print(profile.username) # Lincoln
16
+ print(profile.id) # 10434
17
+
18
+ bal = client.get_balance()
19
+ print(f"Total: {bal.total} ₽ (available {bal.available} ₽, frozen {bal.frozen} ₽)")
20
+
21
+ for p in client.get_my_products():
22
+ print(f"[{p.id}] {p.title} — {p.price} ₽ ({p.status})")
23
+
24
+ client.logout()
25
+ ```
26
+
27
+ See [the full method reference](#api-overview) below.
28
+
29
+ ## Features
30
+
31
+ - 🔐 login / logout / profile / change password
32
+ - 💰 balance, transactions, deposit (lolz, platega, anypay, cryptobot, ...)
33
+ - 📦 products: list / create / update / delete / hide / show / bulk-ops
34
+ - 🚀 bump: free / paid + plugin-based auto-bump
35
+ - 🛒 orders: list, refund, complaint
36
+ - 💬 chat: list conversations, get/send/load older messages, media, pin, delete
37
+ - 🚫 block / mute users + blocklist
38
+ - ❤️ wishlist: check / toggle / add / remove
39
+ - ⭐ reviews: leave / reply / list
40
+ - 🔔 notifications: get / update settings
41
+ - 🔗 integrations: Telegram / VK link & unlink
42
+ - 📊 stats: heatmap, today's earnings, dashboard
43
+
44
+ ## Exception types
45
+
46
+ ```python
47
+ from dipx import (
48
+ AuthError,
49
+ NotFoundError,
50
+ ValidationError,
51
+ InsufficientBalanceError,
52
+ RateLimitError,
53
+ DipXError,
54
+ )
55
+ ```
56
+
57
+ All exceptions carry a `status_code` (HTTP) and optional `payload` (parsed JSON
58
+ body).
59
+
60
+ ## API overview
61
+
62
+ | Group | Methods |
63
+ |-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
64
+ | Auth | `login`, `logout`, `me` |
65
+ | Profile | `get_profile`, `update_profile`, `change_password` |
66
+ | Balance | `get_balance`, `get_transactions`, `create_deposit`, `request_withdrawal` |
67
+ | Products | `get_my_products`, `get_product`, `create_product`, `update_product`, `delete_product`, `hide_product`, `show_product`, `toggle_product_visibility`, `bulk_hide_products`, `bulk_show_products` |
68
+ | Bump | `get_bump_info`, `bump_product`, `bump_all_free`, `setup_auto_bump`, `cancel_auto_bump`, `resume_auto_bump`, `buy_auto_bump_plugin` |
69
+ | Orders | `get_orders`, `get_order`, `request_refund`, `confirm_order`, `cancel_order`, `dispute_order`, `file_complaint` |
70
+ | Chat | `get_conversations`, `get_unread_count`, `get_messages`, `get_older_messages`, `send_message`, `get_media`, `pin_conversation`, `delete_conversation` |
71
+ | Block / Mute | `block_user`, `mute_user`, `get_blocked_users` |
72
+ | Wishlist | `check_wishlist`, `toggle_wishlist`, `add_to_wishlist`, `remove_from_wishlist` |
73
+ | Reviews | `leave_review`, `reply_to_review`, `delete_review_reply`, `get_user_reviews` |
74
+ | Notifications | `get_notification_settings`, `update_notification_settings` |
75
+ | Integrations | `link_telegram`, `unlink_telegram`, `unlink_vk` |
76
+ | Stats | `get_activity_heatmap`, `get_today_earnings`, `get_stats` |
77
+
78
+ ## License
79
+
80
+ MIT
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "dipx"
7
+ version = "0.1.0"
8
+ description = "Python client library for dip-x.store marketplace"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+ authors = [
13
+ { name = "aue.a", email = "aue.a@internet.ru" },
14
+ ]
15
+ keywords = ["dipx", "dip-x", "marketplace", "api"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Software Development :: Libraries :: Python Modules",
26
+ ]
27
+ dependencies = [
28
+ "requests>=2.28",
29
+ "beautifulsoup4>=4.11",
30
+ ]
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/FreezeRust/dipx"
34
+ Issues = "https://github.com/FreezeRust/dipx/issues"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/dipx"]
38
+
39
+ [tool.hatch.build.targets.sdist]
40
+ include = [
41
+ "src/dipx",
42
+ "README.md",
43
+ "LICENSE",
44
+ ]
@@ -0,0 +1,61 @@
1
+ """Python client for the dip-x.store marketplace.
2
+
3
+ Quick start::
4
+
5
+ from dipx import DipXClient
6
+
7
+ client = DipXClient()
8
+ profile = client.login("Lincoln", "password")
9
+ print(profile.username, profile.id)
10
+
11
+ for p in client.get_my_products():
12
+ print(p.id, p.title, p.price, p.status)
13
+
14
+ client.logout()
15
+ """
16
+
17
+ from .client import DipXClient
18
+ from .exceptions import (
19
+ AuthError,
20
+ DipXError,
21
+ InsufficientBalanceError,
22
+ NotFoundError,
23
+ RateLimitError,
24
+ ValidationError,
25
+ )
26
+ from .models import (
27
+ Balance,
28
+ BumpInfo,
29
+ Conversation,
30
+ Message,
31
+ NotificationSettings,
32
+ Order,
33
+ Product,
34
+ Profile,
35
+ Review,
36
+ Transaction,
37
+ WishlistResult,
38
+ )
39
+
40
+ __version__ = "0.1.0"
41
+
42
+ __all__ = [
43
+ "DipXClient",
44
+ "AuthError",
45
+ "DipXError",
46
+ "InsufficientBalanceError",
47
+ "NotFoundError",
48
+ "RateLimitError",
49
+ "ValidationError",
50
+ "Balance",
51
+ "BumpInfo",
52
+ "Conversation",
53
+ "Message",
54
+ "NotificationSettings",
55
+ "Order",
56
+ "Product",
57
+ "Profile",
58
+ "Review",
59
+ "Transaction",
60
+ "WishlistResult",
61
+ ]
@@ -0,0 +1,177 @@
1
+ """Internal HTTP helper: holds a :class:`requests.Session`, manages CSRF.
2
+
3
+ The marketplace authenticates with cookies (PHPSESSID) and rejects most
4
+ JSON endpoints that don't have an ``X-Requested-With: XMLHttpRequest``
5
+ header and a same-origin ``Referer``. CSRF tokens are required by all
6
+ state-mutating endpoints and refreshed on every full HTML page load.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import re
12
+ from typing import Any, Dict, Optional
13
+
14
+ import requests
15
+
16
+ from .exceptions import (
17
+ AuthError,
18
+ DipXError,
19
+ InsufficientBalanceError,
20
+ NotFoundError,
21
+ RateLimitError,
22
+ ValidationError,
23
+ )
24
+
25
+ BASE_URL = "https://dip-x.store"
26
+
27
+ _CSRF_RE = re.compile(
28
+ r'name="csrf_token"\s+value="([0-9a-f]{32,128})"', re.IGNORECASE
29
+ )
30
+
31
+
32
+ class _Http:
33
+ def __init__(
34
+ self,
35
+ *,
36
+ base_url: str = BASE_URL,
37
+ timeout: float = 30.0,
38
+ user_agent: Optional[str] = None,
39
+ ) -> None:
40
+ self.base_url = base_url.rstrip("/")
41
+ self.timeout = timeout
42
+ self.csrf_token: Optional[str] = None
43
+ self.session = requests.Session()
44
+ self.session.headers.update(
45
+ {
46
+ "User-Agent": user_agent
47
+ or (
48
+ "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
49
+ "(KHTML, like Gecko) Chrome/130.0 Safari/537.36"
50
+ ),
51
+ "Accept-Language": "ru,en;q=0.9",
52
+ }
53
+ )
54
+
55
+ # ── url helpers ──────────────────────────────────────────────
56
+ def url(self, path: str) -> str:
57
+ if path.startswith(("http://", "https://")):
58
+ return path
59
+ if not path.startswith("/"):
60
+ path = "/" + path
61
+ return self.base_url + path
62
+
63
+ # ── csrf ────────────────────────────────────────────────────
64
+ def refresh_csrf(self, html: str) -> Optional[str]:
65
+ m = _CSRF_RE.search(html)
66
+ if m:
67
+ self.csrf_token = m.group(1)
68
+ return self.csrf_token
69
+
70
+ def ensure_csrf(self, page_path: str = "/profile") -> str:
71
+ """Make sure we have a CSRF token; load ``page_path`` if needed."""
72
+ if self.csrf_token:
73
+ return self.csrf_token
74
+ resp = self.session.get(self.url(page_path), timeout=self.timeout)
75
+ self.refresh_csrf(resp.text)
76
+ if not self.csrf_token:
77
+ raise AuthError(
78
+ "Не удалось получить csrf_token (вы авторизованы?)",
79
+ status_code=resp.status_code,
80
+ )
81
+ return self.csrf_token
82
+
83
+ # ── core request ────────────────────────────────────────────
84
+ def request(
85
+ self,
86
+ method: str,
87
+ path: str,
88
+ *,
89
+ json: Any = None,
90
+ data: Any = None,
91
+ files: Any = None,
92
+ params: Any = None,
93
+ headers: Optional[Dict[str, str]] = None,
94
+ referer: Optional[str] = None,
95
+ allow_redirects: bool = True,
96
+ as_json: bool = True,
97
+ raise_status: bool = True,
98
+ ) -> Any:
99
+ url = self.url(path)
100
+ hdrs: Dict[str, str] = {}
101
+ if as_json:
102
+ hdrs["X-Requested-With"] = "XMLHttpRequest"
103
+ hdrs["Accept"] = "application/json, text/plain, */*"
104
+ if referer:
105
+ hdrs["Referer"] = self.url(referer)
106
+ if headers:
107
+ hdrs.update(headers)
108
+
109
+ resp = self.session.request(
110
+ method,
111
+ url,
112
+ json=json,
113
+ data=data,
114
+ files=files,
115
+ params=params,
116
+ headers=hdrs,
117
+ timeout=self.timeout,
118
+ allow_redirects=allow_redirects,
119
+ )
120
+
121
+ if raise_status:
122
+ _raise_for_status(resp)
123
+
124
+ if as_json:
125
+ ct = resp.headers.get("Content-Type", "")
126
+ if "application/json" in ct:
127
+ try:
128
+ return resp.json()
129
+ except Exception:
130
+ pass
131
+ return resp
132
+
133
+ def get_json(self, path: str, **kw) -> Any:
134
+ return self.request("GET", path, **kw)
135
+
136
+ def post_json(self, path: str, **kw) -> Any:
137
+ return self.request("POST", path, **kw)
138
+
139
+ def get_html(self, path: str, **kw) -> str:
140
+ kw.setdefault("as_json", False)
141
+ resp = self.request("GET", path, **kw)
142
+ text = resp.text
143
+ self.refresh_csrf(text)
144
+ return text
145
+
146
+
147
+ # ── helpers ─────────────────────────────────────────────────────
148
+ def _payload(resp: requests.Response) -> Any:
149
+ ct = resp.headers.get("Content-Type", "")
150
+ if "application/json" in ct:
151
+ try:
152
+ return resp.json()
153
+ except Exception:
154
+ return None
155
+ return None
156
+
157
+
158
+ def _raise_for_status(resp: requests.Response) -> None:
159
+ code = resp.status_code
160
+ if code < 400:
161
+ return
162
+ body = _payload(resp)
163
+ msg: Any = None
164
+ if isinstance(body, dict):
165
+ msg = body.get("error") or body.get("message") or body.get("detail")
166
+ msg = msg or resp.reason or "HTTP error"
167
+ if code in (401, 403):
168
+ raise AuthError(msg, status_code=code, payload=body)
169
+ if code == 404:
170
+ raise NotFoundError(msg, status_code=code, payload=body)
171
+ if code == 429:
172
+ raise RateLimitError(msg, status_code=code, payload=body)
173
+ if code == 402:
174
+ raise InsufficientBalanceError(msg, status_code=code, payload=body)
175
+ if code in (400, 422):
176
+ raise ValidationError(msg, status_code=code, payload=body)
177
+ raise DipXError(msg, status_code=code, payload=body)
@@ -0,0 +1,157 @@
1
+ """HTML scraping helpers — used wherever the site does not return JSON.
2
+
3
+ The marketplace renders many lists (products, orders, conversations) as
4
+ server-side HTML. We parse them with BeautifulSoup. Keep selectors as
5
+ small and tolerant as possible — the site changes its markup.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from typing import List, Optional
12
+
13
+ from bs4 import BeautifulSoup
14
+
15
+ from .models import Balance, Order, Product, Profile
16
+
17
+
18
+ _NUMBER_RE = re.compile(r"-?\d+(?:[.,]\d+)?")
19
+
20
+
21
+ def _to_float(text: Optional[str]) -> float:
22
+ if not text:
23
+ return 0.0
24
+ m = _NUMBER_RE.search(text.replace("\u00a0", "").replace(" ", ""))
25
+ return float(m.group(0).replace(",", ".")) if m else 0.0
26
+
27
+
28
+ def _to_int(text: Optional[str]) -> int:
29
+ if not text:
30
+ return 0
31
+ m = _NUMBER_RE.search(text.replace("\u00a0", "").replace(" ", ""))
32
+ return int(float(m.group(0).replace(",", "."))) if m else 0
33
+
34
+
35
+ def parse_profile_id_from_html(html: str) -> Optional[int]:
36
+ """Extract user ID from various places it may be embedded."""
37
+ for pat in (
38
+ r'data-user-id="(\d+)"',
39
+ r'"user_id":(\d+)',
40
+ r'"id":(\d+),"username"',
41
+ r'/user/[^"]+"[^>]*data-id="(\d+)"',
42
+ ):
43
+ m = re.search(pat, html)
44
+ if m:
45
+ return int(m.group(1))
46
+ return None
47
+
48
+
49
+ def parse_profile(html: str, *, username: str) -> Profile:
50
+ soup = BeautifulSoup(html, "html.parser")
51
+ uid = parse_profile_id_from_html(html) or 0
52
+ avatar = None
53
+ img = soup.select_one(".profile-card__avatar img, .user-card__avatar img")
54
+ if img and img.get("src"):
55
+ avatar = img["src"]
56
+ return Profile(id=uid, username=username, avatar=avatar)
57
+
58
+
59
+ def parse_balance(html: str) -> Balance:
60
+ """Parse ``/profile/balance`` page into a :class:`Balance`."""
61
+ soup = BeautifulSoup(html, "html.parser")
62
+ total = 0.0
63
+ available = 0.0
64
+ frozen = 0.0
65
+ bv = soup.select_one("#balanceValue, .profile-balance__value")
66
+ if bv:
67
+ total = _to_float(bv.get_text())
68
+ # Some pages expose frozen/available in chips:
69
+ for chip in soup.select(".balance-chip, .profile-balance__chip, .balance-block"):
70
+ txt = chip.get_text(" ", strip=True).lower()
71
+ if "доступ" in txt:
72
+ available = _to_float(txt) or available
73
+ elif "заморож" in txt or "холд" in txt:
74
+ frozen = _to_float(txt) or frozen
75
+ # Withdrawal form gives a hard upper bound on available
76
+ inp = soup.select_one('form#withdrawalForm input[name="amount"]')
77
+ if inp and inp.get("max"):
78
+ try:
79
+ available = max(available, float(inp["max"]))
80
+ except ValueError:
81
+ pass
82
+ if available == 0.0 and frozen == 0.0:
83
+ available = total
84
+ return Balance(total=total, available=available, frozen=frozen)
85
+
86
+
87
+ def parse_products(html: str) -> List[Product]:
88
+ soup = BeautifulSoup(html, "html.parser")
89
+ out: List[Product] = []
90
+ for row in soup.select(".product-row"):
91
+ pid = row.get("data-id") or row.get("data-product-id") or "0"
92
+ status = row.get("data-status") or "active"
93
+ title_el = row.select_one(".product-row__title")
94
+ price_el = row.select_one(".product-row__price")
95
+ views_el = row.select_one(".product-row__views")
96
+ sales_el = row.select_one(".product-row__sales")
97
+ date_el = row.select_one(".product-row__date")
98
+ link_el = row.select_one(".product-row__main, a[href*='/product/']")
99
+ img_el = row.select_one(".product-row__image img")
100
+ out.append(
101
+ Product(
102
+ id=int(pid) if str(pid).isdigit() else 0,
103
+ title=title_el.get_text(strip=True) if title_el else "",
104
+ price=_to_float(price_el.get_text() if price_el else ""),
105
+ status=status,
106
+ views=_to_int(views_el.get_text() if views_el else ""),
107
+ sales=_to_int(sales_el.get_text() if sales_el else ""),
108
+ url=link_el.get("href") if link_el else None,
109
+ image=img_el.get("src") if img_el else None,
110
+ created_at=date_el.get_text(strip=True) if date_el else None,
111
+ )
112
+ )
113
+ return out
114
+
115
+
116
+ def parse_orders(html: str, *, role: str) -> List[Order]:
117
+ soup = BeautifulSoup(html, "html.parser")
118
+ out: List[Order] = []
119
+ for row in soup.select(".order-row"):
120
+ link = row.select_one("a[href*='/order/']")
121
+ oid = 0
122
+ if link and link.get("href"):
123
+ m = re.search(r"/order/(\d+)", link["href"])
124
+ if m:
125
+ oid = int(m.group(1))
126
+ title_el = row.select_one(".order-row__title")
127
+ price_el = row.select_one(".order-row__price")
128
+ date_el = row.select_one(".order-row__date")
129
+ user_el = row.select_one(".order-row__user")
130
+ badge_el = row.select_one(".badge, .order-row__status")
131
+ status = "unknown"
132
+ if badge_el:
133
+ txt = badge_el.get_text(strip=True).lower()
134
+ if "заверш" in txt or "выпол" in txt:
135
+ status = "completed"
136
+ elif "ожид" in txt or "пенд" in txt:
137
+ status = "pending"
138
+ elif "отмен" in txt:
139
+ status = "cancelled"
140
+ elif "возвр" in txt or "refund" in txt:
141
+ status = "refunded"
142
+ elif "спор" in txt or "dispute" in txt:
143
+ status = "disputed"
144
+ else:
145
+ status = txt
146
+ out.append(
147
+ Order(
148
+ id=oid,
149
+ product_title=title_el.get_text(strip=True) if title_el else "",
150
+ amount=_to_float(price_el.get_text() if price_el else ""),
151
+ status=status,
152
+ role=role,
153
+ partner=user_el.get_text(strip=True) if user_el else "",
154
+ date=date_el.get_text(strip=True) if date_el else None,
155
+ )
156
+ )
157
+ return out