Skip to content
Permalink
Browse files
Team Discussion
  • Loading branch information
yuz30 committed May 16, 2024
1 parent c16bb4f commit dfd858e9dc28d76f16a1ec08ac654b96bbfd0cd0
Showing 1 changed file with 39 additions and 1 deletion.
@@ -1 +1,39 @@
print("hello")
import requests
import json
from datetime import datetime


def post_message(url, message, scheduled_time=None):
headers = {"Content-Type": "application/json"}

if scheduled_time:
# Scheduled message
data = {
"time": scheduled_time.strftime("%Y-%m-%d %H:%M:%S"),
"message": message
}
else:
# Real-time message
data = {
"time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"message": message
}

response = requests.post(url, headers=headers, data=json.dumps(data))

if response.status_code == 200:
print("Response:", response.json())
else:
print("Failed to send message:", response.status_code, response.text)


# Example usage
url = "http://localhost:8000"
message = "This is a broadcast message."

# For real-time message
post_message(url, message)

# For scheduled message
scheduled_time = datetime(2024, 5, 16, 19, 51, 0)
post_message(url, message, scheduled_time)

0 comments on commit dfd858e

Please sign in to comment.