Files
Free-Telegram-Finder/api.py
T
2026-07-14 08:59:05 +05:00

95 lines
2.9 KiB
Python

import json
from config import (
API_FILTER_COUNT_URL,
API_LIST_URL,
CITY,
CITY_ID,
LIST_URL,
PAGE_SIZE,
HEADERS,
)
async def fetch_main(session):
async with session.get(LIST_URL, headers=HEADERS) as response:
if response.status != 200:
raise ValueError(f"Ошибка при получении страницы: {response.status}")
return await response.text()
async def fetch_filter_count(session, nonce):
form_data = {
"_wpnonce": nonce,
"filterParams": json.dumps(
{
"metro": [],
"is_indi": False,
"is_salon": False,
"is_elite_indi": False,
"is_elite_salon": False,
"base_price_from": 0,
"base_price_to": 0,
"online": False,
"is_new": False,
"is_visited": False,
"massage_pro": False,
"master_tantra": False,
"popular_blogger": False,
"meet_place": [],
"age_from": "",
"age_to": "",
"body_shape": [],
"height": [],
"breast": [],
"groups_photo": [],
"prefers": [],
"city": CITY,
},
separators=(",", ":"),
),
}
async with session.post(
API_FILTER_COUNT_URL, headers=HEADERS, data=form_data
) as response:
if response.status != 200:
raise ValueError(
f"Ошибка при получении количества фильтров: {response.status}"
)
text = json.loads(await response.text())
return text.get("result", 0)
async def fetch_single_page(session, page_id, nonce, args):
form_data = {
"_wpnonce": nonce,
"page": str(page_id),
"number": str(PAGE_SIZE),
"filters": json.dumps(
{
"is_indi_work": True,
"not_statuses": ["nophoto"],
"is_not_hide_salon": True,
"is_not_onhold": True,
"is_active": True,
"city": CITY_ID,
"post_statuses": ["publish"],
},
separators=(",", ":"),
),
"queue": "[]",
"isShuffle": "true",
"sort": json.dumps({"order": "DESC", "by": "height"}, separators=(",", ":")),
"args": json.dumps(args, separators=(",", ":")),
}
async with session.post(API_LIST_URL, headers=HEADERS, data=form_data) as response:
if response.status != 200:
raise ValueError(
f"Ошибка при получении данных страницы {page_id}: {response.status}"
)
text = json.loads(await response.text())
print(f"Страница {page_id}: получено {text.get('length', 0)} анкет")
return text.get("result", "")