Spaces:
Sleeping
Sleeping
Update admin_messages.py
Browse files- admin_messages.py +11 -4
admin_messages.py
CHANGED
@@ -20,9 +20,15 @@ def extract_admin_message(ai_response):
|
|
20 |
|
21 |
def save_admin_message(page_id, message, sender_id, full_name):
|
22 |
"""
|
23 |
-
Save admin message to the GitHub JSON file.
|
24 |
"""
|
25 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Fetch current JSON data
|
27 |
github_response = fetch_json_from_github()
|
28 |
if not github_response["success"]:
|
@@ -36,11 +42,12 @@ def save_admin_message(page_id, message, sender_id, full_name):
|
|
36 |
if page_id not in data:
|
37 |
data[page_id] = []
|
38 |
|
39 |
-
# Add the new message with sender_id and
|
40 |
new_message = {
|
41 |
"message": message,
|
42 |
"sender_id": sender_id,
|
43 |
-
"full_name": full_name if full_name else "Unknown User"
|
|
|
44 |
}
|
45 |
|
46 |
data[page_id].append(new_message)
|
@@ -58,7 +65,7 @@ def save_admin_message(page_id, message, sender_id, full_name):
|
|
58 |
# Update the file on GitHub
|
59 |
update_result = update_user_json_file(authenticity_token, commit_oid, new_content)
|
60 |
if update_result["success"]:
|
61 |
-
print("Admin message saved successfully")
|
62 |
return True
|
63 |
else:
|
64 |
print(f"Error saving admin message: {update_result['message']}")
|
|
|
20 |
|
21 |
def save_admin_message(page_id, message, sender_id, full_name):
|
22 |
"""
|
23 |
+
Save admin message to the GitHub JSON file with date and time.
|
24 |
"""
|
25 |
try:
|
26 |
+
# Import datetime module for timestamp
|
27 |
+
from datetime import datetime
|
28 |
+
|
29 |
+
# Get current date and time in ISO format
|
30 |
+
timestamp = datetime.now().isoformat()
|
31 |
+
|
32 |
# Fetch current JSON data
|
33 |
github_response = fetch_json_from_github()
|
34 |
if not github_response["success"]:
|
|
|
42 |
if page_id not in data:
|
43 |
data[page_id] = []
|
44 |
|
45 |
+
# Add the new message with sender_id, full_name, and timestamp
|
46 |
new_message = {
|
47 |
"message": message,
|
48 |
"sender_id": sender_id,
|
49 |
+
"full_name": full_name if full_name else "Unknown User",
|
50 |
+
"timestamp": timestamp
|
51 |
}
|
52 |
|
53 |
data[page_id].append(new_message)
|
|
|
65 |
# Update the file on GitHub
|
66 |
update_result = update_user_json_file(authenticity_token, commit_oid, new_content)
|
67 |
if update_result["success"]:
|
68 |
+
print(f"Admin message saved successfully with timestamp: {timestamp}")
|
69 |
return True
|
70 |
else:
|
71 |
print(f"Error saving admin message: {update_result['message']}")
|