add time
This commit is contained in:
		
							
								
								
									
										20
									
								
								listen.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								listen.py
									
									
									
									
									
								
							@@ -2,6 +2,7 @@ import os
 | 
			
		||||
from dotenv import load_dotenv
 | 
			
		||||
from pyrogram import Client, filters
 | 
			
		||||
from flask import Flask, render_template_string, request, Response
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
 | 
			
		||||
# Load environment variables from .env file
 | 
			
		||||
load_dotenv()
 | 
			
		||||
@@ -27,10 +28,15 @@ messages = []
 | 
			
		||||
def handle_message(client, message):
 | 
			
		||||
    # Check if the message contains the specific string
 | 
			
		||||
    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
 | 
			
		||||
        formatted_message = message.text.replace("\n", "<br>")
 | 
			
		||||
        # Add the formatted message to the list
 | 
			
		||||
        messages.append(formatted_message)
 | 
			
		||||
        # Add the formatted message and received time to the list
 | 
			
		||||
        messages.append({
 | 
			
		||||
            "text": formatted_message,
 | 
			
		||||
            "time": received_time
 | 
			
		||||
        })
 | 
			
		||||
        # Keep only the last 50 messages (optional)
 | 
			
		||||
        if len(messages) > 50:
 | 
			
		||||
            messages.pop(0)
 | 
			
		||||
@@ -88,12 +94,20 @@ def index():
 | 
			
		||||
                .message:last-child {
 | 
			
		||||
                    margin-bottom: 0;
 | 
			
		||||
                }
 | 
			
		||||
                .message-time {
 | 
			
		||||
                    font-size: 0.8em;
 | 
			
		||||
                    color: #666;
 | 
			
		||||
                    margin-bottom: 5px;
 | 
			
		||||
                }
 | 
			
		||||
            </style>
 | 
			
		||||
        </head>
 | 
			
		||||
        <body>
 | 
			
		||||
            <div class="messages-container">
 | 
			
		||||
                {% 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 %}
 | 
			
		||||
            </div>
 | 
			
		||||
        </body>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user