Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,39 +19,34 @@ logger = logging.getLogger(__name__)
|
|
| 19 |
# Initialize Flask app
|
| 20 |
app = Flask(__name__)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
"chat_id": TELEGRAM_CHAT_ID,
|
| 32 |
-
"text": message,
|
| 33 |
-
"parse_mode": "HTML"
|
| 34 |
}
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
"
|
| 38 |
-
"parse_mode": "HTML"
|
| 39 |
}
|
|
|
|
| 40 |
try:
|
| 41 |
-
logger.info(
|
| 42 |
-
response = requests.post(
|
| 43 |
-
|
| 44 |
response_json = response.json()
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
logger.error(f"Telegram API error: {response_json.get('description', 'Unknown error')}")
|
| 51 |
-
return None
|
| 52 |
except Exception as e:
|
| 53 |
-
logger.error(f"
|
| 54 |
-
return
|
| 55 |
|
| 56 |
def get_active_signals():
|
| 57 |
"""Get all active signals from the signals database"""
|
|
@@ -213,9 +208,9 @@ def format_telegram_message(signal_data):
|
|
| 213 |
message = "🔔 <b>إشارة فوركس جديدة</b> 🔔\n\n"
|
| 214 |
message += f"<b>🔹 الزوج:</b> {signal_data['pair']}\n"
|
| 215 |
message += f"<b>📊 النوع:</b> {signal_data['type']}\n"
|
| 216 |
-
message += f"<b>🎯 الد
|
| 217 |
message += f"<b>🛡️ وقف الخسارة:</b> {signal_data['stop_loss']}\n"
|
| 218 |
-
message += f"<b>
|
| 219 |
|
| 220 |
return message
|
| 221 |
|
|
@@ -278,15 +273,15 @@ def analyze_forex_groups():
|
|
| 278 |
if update_signals_file(signal_data, pairs):
|
| 279 |
logger.info(f"Signal for group {group_key} saved successfully")
|
| 280 |
|
| 281 |
-
# Format and send
|
| 282 |
-
|
| 283 |
-
logger.info("Attempting to send
|
| 284 |
-
|
| 285 |
|
| 286 |
-
if
|
| 287 |
-
logger.info(f"
|
| 288 |
else:
|
| 289 |
-
logger.error(f"Failed to send
|
| 290 |
|
| 291 |
# Remove the group from deeper.json
|
| 292 |
if remove_group_from_deeper(group_key):
|
|
|
|
| 19 |
# Initialize Flask app
|
| 20 |
app = Flask(__name__)
|
| 21 |
|
| 22 |
+
# Message API configuration
|
| 23 |
+
MESSAGE_API_URL = "https://aoamrnuwara.pythonanywhere.com/api/send-message"
|
| 24 |
+
MESSAGE_API_KEY = "Seakp0683asppoit"
|
| 25 |
+
|
| 26 |
+
def send_message_to_api(message):
|
| 27 |
+
"""Send a message via the message forwarding API."""
|
| 28 |
+
headers = {
|
| 29 |
+
"Content-Type": "application/json",
|
| 30 |
+
"X-API-Key": MESSAGE_API_KEY
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
+
|
| 33 |
+
payload = {
|
| 34 |
+
"message": message
|
|
|
|
| 35 |
}
|
| 36 |
+
|
| 37 |
try:
|
| 38 |
+
logger.info("Sending message via API")
|
| 39 |
+
response = requests.post(MESSAGE_API_URL, headers=headers, data=json.dumps(payload))
|
| 40 |
+
response.raise_for_status()
|
| 41 |
response_json = response.json()
|
| 42 |
+
logger.info(f"Message sent to API successfully. Status Code: {response.status_code}")
|
| 43 |
+
return {"success": True, "response": response_json}
|
| 44 |
+
except requests.exceptions.RequestException as e:
|
| 45 |
+
logger.error(f"API request error: {e}", exc_info=True)
|
| 46 |
+
return {"success": False, "error": str(e)}
|
|
|
|
|
|
|
| 47 |
except Exception as e:
|
| 48 |
+
logger.error(f"Unexpected error sending message to API: {e}", exc_info=True)
|
| 49 |
+
return {"success": False, "error": str(e)}
|
| 50 |
|
| 51 |
def get_active_signals():
|
| 52 |
"""Get all active signals from the signals database"""
|
|
|
|
| 208 |
message = "🔔 <b>إشارة فوركس جديدة</b> 🔔\n\n"
|
| 209 |
message += f"<b>🔹 الزوج:</b> {signal_data['pair']}\n"
|
| 210 |
message += f"<b>📊 النوع:</b> {signal_data['type']}\n"
|
| 211 |
+
message += f"<b>🎯 الد��ول:</b> {signal_data['entry']}\n"
|
| 212 |
message += f"<b>🛡️ وقف الخسارة:</b> {signal_data['stop_loss']}\n"
|
| 213 |
+
message += f"<b>💰 الهدف:</b> {signal_data['take_profit']}\n"
|
| 214 |
|
| 215 |
return message
|
| 216 |
|
|
|
|
| 273 |
if update_signals_file(signal_data, pairs):
|
| 274 |
logger.info(f"Signal for group {group_key} saved successfully")
|
| 275 |
|
| 276 |
+
# Format message and send via API instead of directly to Telegram
|
| 277 |
+
formatted_message = format_telegram_message(signal_data)
|
| 278 |
+
logger.info("Attempting to send message via API...")
|
| 279 |
+
api_response = send_message_to_api(formatted_message)
|
| 280 |
|
| 281 |
+
if api_response["success"]:
|
| 282 |
+
logger.info(f"Message for group {group_key} sent successfully via API")
|
| 283 |
else:
|
| 284 |
+
logger.error(f"Failed to send message for group {group_key} via API. Error: {api_response.get('error')}")
|
| 285 |
|
| 286 |
# Remove the group from deeper.json
|
| 287 |
if remove_group_from_deeper(group_key):
|