#!/usr/bin/python3 import os from datetime import datetime, timezone import requests schedule_start = datetime.fromisoformat("2021-11-12T10:00") since_start = datetime.utcnow() - schedule_start if since_start.days < 0: exit() hour = since_start.days * 24 + since_start.seconds // 3600 filename = '/DB15-Volunteer-Schedule-raw.csv' coming_online = [] going_offline = [] with open(filename, 'r') as schedule_file: 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])) print(coming_online) print(going_offline) message = f"**Shift changes for :**\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" 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)