Skip to content

Instantly share code, notes, and snippets.

@HarHarLinks
Last active January 2, 2022 10:59
Show Gist options
  • Save HarHarLinks/4df87f52c7df78690b903d1a53f4d927 to your computer and use it in GitHub Desktop.
Save HarHarLinks/4df87f52c7df78690b903d1a53f4d927 to your computer and use it in GitHub Desktop.
Manage a series of reminders for https://github.com/anoadragon453/matrix-reminder-bot
#!/usr/bin/env python
# This code is provided free of charge without any liability or guarantees.
# (c) HarHarLinks (https://github.com/HarHarLinks)
# This tool is supposed to ease interaction with matrix-reminder-bot
# https://github.com/anoadragon453/matrix-reminder-bot
# This tool builds upon matrix.sh and you need to install (download) it yourself
# https://github.com/fabianonline/matrix.sh
# Edit the below variable matrixsh to set its path
# To use this script, edit the stepN variables (minutes=X)
# and the respective notification text.
# Obviously oyu can remove or add more steps to fit your case.
from datetime import timedelta, datetime
import argparse
import subprocess as sp
matrixsh = './matrix.sh'
def calcReminder(input_time: str, action: str = 'r') -> list[str]:
five = timedelta(minutes=5)
step = list()
step.append((datetime.strptime(input_time, "%H:%M"), " - First in a series"))
step.append((step[0][0] + timedelta(minutes=20), " - Second in a series"))
step.append((step[1][0] + timedelta(minutes=30), " - Third in a series"))
step.append((step[2][0] + timedelta(minutes=30), " - Fourth in a series"))
step.append((step[3][0] + timedelta(minutes=10), " - Fifth in a series"))
if action in ['c']:
return [f"!{action} {t:%H:%M}{d}" for t,d in step]
else:
return [f"!{action} {t - five:%H:%M}; {t:%H:%M}{d}" for t,d in step]
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Manage multiple reminders at once")
parser.add_argument('--reminder', '-r', help="Create reminders at given time")
parser.add_argument('--alarm', '-a', help="Create alarm reminders at given time")
parser.add_argument('--cancel', '-c', help="Cancel reminders starting at given time")
parser.add_argument('room', help="The room to send reminders to, e.g. !0123456789abcdefghi:example.org")
args = parser.parse_args()
if args.cancel:
reminders = calcReminder(args.cancel, 'c')
print(reminders)
for r in reminders:
sp.run([matrixsh, f'--room={args.room}', r])
if args.reminder:
reminders = calcReminder(args.reminder)
print(reminders)
for r in reminders:
sp.run([matrixsh, f'--room={args.room}', r])
if args.alarm:
reminders = calcReminder(args.alarm, 'a')
print(reminders)
for r in reminders:
sp.run([matrixsh, f'--room={args.room}', r])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment