commit f296f8d0e45a22982073847bd1edacfc7b7c1f8b
parent 4c17bbbf643dbd6f9c70e795cc5964a5ff5c63f9
Author: Vetle Haflan <vetle@haflan.dev>
Date: Thu, 3 Sep 2020 07:58:54 +0200
Qumpify date-events.py
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/date-events.py b/date-events.py
@@ -1,19 +1,22 @@
#!/usr/bin/python3
+import pyqump
import requests
import re
from datetime import datetime
from os.path import expanduser
HOME=expanduser('~')
+qump_token = open(HOME + '/.qump-token').read().strip()
+pyqump.init(token = qump_token, server = 'https://haflan.dev')
# Quickfix to get date from midnight
date_today = datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)
def get_events():
date_re = re.compile('\d{2}-\d{2}')
- # TODO: Get string from qump?
- event_strs = open(HOME + '/scripts/date-events.txt').read().splitlines()
+ # Get all lines of '/remind|/event' qumps
+ event_strs = '\n'.join(t['text'] for t in pyqump.load(regex='^/remind')).splitlines()
event_dates = []
for e in event_strs[1:]:
if not e:
@@ -23,12 +26,8 @@ def get_events():
dt = datetime.strptime(match.group(0), '%m-%d').replace(year = date_today.year)
text = e.split(' ', 1)[1]
event_dates.append({ 'date': dt, 'text': text })
- else:
- print('Malformed event line: ' + e)
- continue
return event_dates
-# Report with Gotify - this can of course be changed to whatever reporting service
def report(message):
gotify_token = open(HOME + '/.gotify-token').read().splitlines()[0]
headers = { 'X-Gotify-Key': gotify_token }
@@ -56,4 +55,6 @@ if in_week:
for e in in_week:
message += '- ' + str(e['date'].strftime('%A')) + ': ' + e['text'] + '\n'
+if not message:
+ message = 'Nothing happening this week'
report(message)