You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB
Python

3 years ago
#!/usr/bin/python3
import os
from datetime import datetime, timezone
import requests
filename = os.environ["SCHEDULE_FILE"]
3 years ago
coming_online = []
going_offline = []
with open(filename, 'r') as schedule_file:
hours = [datetime.fromisoformat(hour_string + "-08:00") for hour_string in schedule_file.readline().split(",")[1:]]
current_time = datetime.now(timezone.utc).replace(minute=0, second=0, microsecond=0)
print(current_time)
print(hours)
for (hour, timestamp) in enumerate(hours, 1):
if timestamp == current_time:
break
3 years ago
for line in schedule_file:
cells = line.split(",")
if cells[hour] != cells[hour - 1]:
if cells[hour] == "":
going_offline.append((cells[0], cells[hour - 1]))
else:
coming_online.append((cells[0], cells[hour]))
if hour == 1:
exit(0)
3 years ago
print(coming_online)
print(going_offline)
message = f"**Shift changes for <time:{datetime.now(timezone.utc).isoformat(timespec='minutes')}>:**\n"
message += "Make sure to *mute/unmute* #**current-shift** as needed!\n"
3 years ago
message += "\n---\n"
message += "Coming online:\n"
for (person, role) in coming_online:
message += f"- *{person}* - {role}\n"
message += "\n---\n"
message += "Going offline:\n"
for (person, role) in going_offline:
message += f"- *{person}* - {role}\n"
message += "\n---\n"
3 years ago
print(message)
bot_email = os.environ["BOT_EMAIL"]
api_key = os.environ["BOT_API_KEY"]
message_request = {
"type": "stream",
"to": "technical",
"topic": "Schedule bot",
"content": message,
}
r = requests.post('https://chat.videostrike.team/api/v1/messages',
data=message_request,
auth=(bot_email, api_key)
)
print(r.status_code)