This commit is contained in:
2025-02-21 16:57:48 +05:00
parent be5d1d3382
commit 610eda93b6

View File

@@ -2,6 +2,7 @@ import os
from dotenv import load_dotenv from dotenv import load_dotenv
from pyrogram import Client, filters from pyrogram import Client, filters
from flask import Flask, render_template_string, request, Response from flask import Flask, render_template_string, request, Response
from datetime import datetime
# Load environment variables from .env file # Load environment variables from .env file
load_dotenv() load_dotenv()
@@ -27,10 +28,15 @@ messages = []
def handle_message(client, message): def handle_message(client, message):
# Check if the message contains the specific string # Check if the message contains the specific string
if "[SIM2(Dhiraagu) Receive SMS]" in message.text: if "[SIM2(Dhiraagu) Receive SMS]" in message.text:
# Format the received time
received_time = message.date.strftime("%Y-%m-%d %H:%M:%S")
# Replace newlines with <br> tags for HTML rendering # Replace newlines with <br> tags for HTML rendering
formatted_message = message.text.replace("\n", "<br>") formatted_message = message.text.replace("\n", "<br>")
# Add the formatted message to the list # Add the formatted message and received time to the list
messages.append(formatted_message) messages.append({
"text": formatted_message,
"time": received_time
})
# Keep only the last 50 messages (optional) # Keep only the last 50 messages (optional)
if len(messages) > 50: if len(messages) > 50:
messages.pop(0) messages.pop(0)
@@ -88,12 +94,20 @@ def index():
.message:last-child { .message:last-child {
margin-bottom: 0; margin-bottom: 0;
} }
.message-time {
font-size: 0.8em;
color: #666;
margin-bottom: 5px;
}
</style> </style>
</head> </head>
<body> <body>
<div class="messages-container"> <div class="messages-container">
{% for message in messages %} {% for message in messages %}
<div class="message">{{ message | safe }}</div> <div class="message">
<div class="message-time">{{ message.time }}</div>
<div>{{ message.text | safe }}</div>
</div>
{% endfor %} {% endfor %}
</div> </div>
</body> </body>