|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
import requests
|
|
|
|
|
|
|
|
filename = os.environ["SCHEDULE_FILE"]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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"
|
|
|
|
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"
|
|
|
|
|
|
|
|
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)
|