Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1485,52 +1485,59 @@ def add_user_senler_full():
|
|
1485 |
|
1486 |
# Проверка групп СЕНДЛЕРА на рассылку
|
1487 |
@app.route('/get_Lo_Mess_senler', methods=['POST'])
|
1488 |
-
def
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1492 |
|
1493 |
-
|
1494 |
-
|
1495 |
-
return jsonify({"status": "error", "message": "Missing required parameters"}), 400
|
1496 |
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
1501 |
-
"Authorization": f"Bearer {senler_token}"
|
1502 |
-
}
|
1503 |
-
payload = {
|
1504 |
-
"vk_user_id": [vk_user_id],
|
1505 |
-
"count": 1
|
1506 |
-
}
|
1507 |
|
1508 |
-
|
1509 |
-
|
1510 |
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
|
|
1514 |
|
1515 |
-
|
1516 |
-
|
|
|
1517 |
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
|
|
|
|
1521 |
|
1522 |
-
|
1523 |
-
if not data.get("items"):
|
1524 |
return jsonify({"status": "not"}), 200
|
1525 |
|
1526 |
-
|
1527 |
-
|
1528 |
-
|
1529 |
-
if subscription.get("subscription_id") == int(subscription_id):
|
1530 |
-
return jsonify({"status": "1"}), 200
|
1531 |
-
|
1532 |
-
# Если группа не найдена
|
1533 |
-
return jsonify({"status": "not"}), 200
|
1534 |
|
1535 |
|
1536 |
|
|
|
1485 |
|
1486 |
# Проверка групп СЕНДЛЕРА на рассылку
|
1487 |
@app.route('/get_Lo_Mess_senler', methods=['POST'])
|
1488 |
+
def get_Lo_Mess_senler():
|
1489 |
+
try:
|
1490 |
+
# Получаем параметры из POST-запроса, если параметр отсутствует, устанавливаем значение пустой строки
|
1491 |
+
vk_user_id = request.form.get('vk_user_id', "")
|
1492 |
+
subscription_id = request.form.get('sub_id', "")
|
1493 |
+
|
1494 |
+
# Проверяем, что оба параметра переданы
|
1495 |
+
if not vk_user_id or not subscription_id:
|
1496 |
+
return jsonify({"status": "error", "message": "Missing required parameters"}), 400
|
1497 |
+
|
1498 |
+
# Формируем URL для запроса к API Senler
|
1499 |
+
url = "https://api.senler.ru/v1/subscribers/get"
|
1500 |
+
headers = {
|
1501 |
+
"Content-Type": "application/json",
|
1502 |
+
"Authorization": f"Bearer {senler_token}"
|
1503 |
+
}
|
1504 |
+
payload = {
|
1505 |
+
"vk_user_id": [vk_user_id],
|
1506 |
+
"count": 1
|
1507 |
+
}
|
1508 |
|
1509 |
+
# Выполняем запрос к API Senler
|
1510 |
+
response = requests.post(url, headers=headers, json=payload)
|
|
|
1511 |
|
1512 |
+
# Проверяем статус ответа
|
1513 |
+
if response.status_code != 200:
|
1514 |
+
logging.error(f"Failed to fetch data from Senler API: {response.status_code} - {response.text}")
|
1515 |
+
return jsonify({"status": "error", "message": "Failed to fetch data from Senler API"}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
1516 |
|
1517 |
+
# Парсим ответ
|
1518 |
+
data = response.json()
|
1519 |
|
1520 |
+
# Проверяем успешность запроса
|
1521 |
+
if not data.get("success"):
|
1522 |
+
logging.error(f"Senler API request failed: {data.get('error', {}).get('message', 'Unknown error')}")
|
1523 |
+
return jsonify({"status": "error", "message": "Senler API request failed"}), 500
|
1524 |
|
1525 |
+
# Проверяем, есть ли пользователь в ответе
|
1526 |
+
if not data.get("items"):
|
1527 |
+
return jsonify({"status": "not"}), 200
|
1528 |
|
1529 |
+
# Проверяем, есть ли указанная группа в массиве subscriptions
|
1530 |
+
for subscriber in data["items"]:
|
1531 |
+
for subscription in subscriber.get("subscriptions", []):
|
1532 |
+
if subscription.get("subscription_id") == int(subscription_id):
|
1533 |
+
return jsonify({"status": "1"}), 200
|
1534 |
|
1535 |
+
# Если группа не найдена
|
|
|
1536 |
return jsonify({"status": "not"}), 200
|
1537 |
|
1538 |
+
except Exception as e:
|
1539 |
+
logging.error(f"An error occurred: {str(e)}")
|
1540 |
+
return jsonify({"status": "error", "message": str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
1541 |
|
1542 |
|
1543 |
|