diff options
| author | Anton Bobov <abobov@gmail.com> | 2020-10-25 20:27:52 +0500 |
|---|---|---|
| committer | Anton Bobov <abobov@gmail.com> | 2020-10-25 20:27:52 +0500 |
| commit | 98fea5f02034cb1f3b83b6c4c7dae757ac4b1c1d (patch) | |
| tree | ee4cacd87d19a9525b58659c15584b2cb97ef5f8 | |
| parent | d449097301953bbd626433814cab5aa0680e3aca (diff) | |
Updates.
| -rwxr-xr-x | $ | 2 | ||||
| -rwxr-xr-x | d-backup | 6 | ||||
| -rwxr-xr-x | genmon-remind.sh | 19 | ||||
| -rwxr-xr-x | rem2ics | 92 | ||||
| -rwxr-xr-x | sync-rem.sh | 9 |
5 files changed, 126 insertions, 2 deletions
@@ -0,0 +1,2 @@ +#!/bin/sh +exec "$@" @@ -13,6 +13,8 @@ if [ ! $(whoami) = root ] ; then fi HOME=/home/anton +REMOVE_ALL_BUT_N_FULL=4 +FULL_IF_OLDER_THAN=3M source "$HOME/.duplicity.conf" SOURCE=/ @@ -33,14 +35,14 @@ EOF backup() { nice ionice duplicity $DUPLICITY_OPTS \ --exclude-filelist "$HOME/.duplicity-exclude" \ - --full-if-older-than 2M \ + --full-if-older-than "$FULL_IF_OLDER_THAN" \ "$SOURCE" "$TARGET" cleanup } cleanup() { duplicity $DUPLICITY_OPTS cleanup --force "$TARGET" - duplicity $DUPLICITY_OPTS remove-all-but-n-full 3 --force "$TARGET" + duplicity $DUPLICITY_OPTS remove-all-but-n-full $REMOVE_ALL_BUT_N_FULL --force "$TARGET" } stats() { diff --git a/genmon-remind.sh b/genmon-remind.sh new file mode 100755 index 0000000..fd726dd --- /dev/null +++ b/genmon-remind.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +TODAY_REMINDERS=$(rem -r -k'echo 1' | wc -l) +CAL_IMG="/usr/share/icons/Adwaita/scalable/mimetypes/x-office-calendar-symbolic.svg" + +if [ -f "$CAL_IMG" ] ; then + echo "<img>$CAL_IMG</img>" +fi +[ $TODAY_REMINDERS -gt 0 ] && echo "<txt> $TODAY_REMINDERS</txt>" +echo "<click>tkremind -m -b1 </click>" +echo "<tool>" +echo "<span font_family='monospace' size='small'>" +rem +echo +task rc.color=off genmon +echo "</span>" +echo "</tool>" @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +# +# Converts output of remind to ICS format: +# +# Usage example: rem -ppp12 | rem2ics +# +# https://tools.ietf.org/html/rfc5545 +import datetime +import json +import sys +from datetime import datetime, timedelta, timezone +from os.path import basename, splitext + + +class Event: + def __init__(self, uid, event_json): + self.event_json = event_json + self.uid = uid + + def summary(self): + e = self.event_json + summary = e.get('body', '').replace(r'%"', '') + if 'time' in e: + summary = summary[6:] + if 'passthru' in e and 'COLOR' in e['passthru']: + summary = ' '.join(summary.split(' ')[3:]) + return summary + + def categories(self): + filename = basename(self.event_json['filename'].upper()) + return splitext(filename)[0] + + def dtstart(self): + e = self.event_json + if 'eventstart' in e: + dt = datetime.strptime(e['eventstart'], '%Y-%m-%dT%H:%M') + return self.__datetime_format(dt) + return e['date'].replace('-', '') + + def dtend(self): + e = self.event_json + if 'rep' in e and 'until' in e: + dt = datetime.strptime(e['until'], '%Y-%m-%d') + return (dt + timedelta(days=1)).strftime('%Y%m%d') + elif 'eventduration' in e and 'eventstart' in e: + dt = datetime.strptime(e['eventstart'], '%Y-%m-%dT%H:%M') + return self.__datetime_format(dt + timedelta(minutes=int(e['eventduration']))) + return self.dtstart() + + @staticmethod + def __datetime_format(dt): + return dt.astimezone(timezone.utc).strftime('%Y%m%dT%H%M%SZ') + + +def create_uid(event): + if 'rep' in event and 'until' in event: + date = event['until'] + else: + date = event['date'] + return "%s:%s:%s" % (basename(event['filename']), event['lineno'], date) + + +def print_ics(events): + print('BEGIN:VCALENDAR') + print('VERSION:2.0') + for event in events: + print('BEGIN:VEVENT') + print('UID:%s' % event.uid) + print('DTSTART:%s' % event.dtstart()) + print('DTEND:%s' % event.dtend()) + print('SUMMARY:%s' % event.summary()) + print('CATEGORIES:%s' % event.categories()) + print('END:VEVENT') + print('END:VCALENDAR') + + +def rem2ics(): + added = set() + events = [] + data = json.load(sys.stdin) + for month in data: + for event_json in month['entries']: + uid = create_uid(event_json) + if uid in added: + continue + added.add(uid) + events.append(Event(uid, event_json)) + print_ics(events) + + +if __name__ == '__main__': + rem2ics() diff --git a/sync-rem.sh b/sync-rem.sh new file mode 100755 index 0000000..da88dc2 --- /dev/null +++ b/sync-rem.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +PREV_MONTHS=2 +MONTHS=$((12 + PREV_MONTHS)) +START=$(date --date "$PREV_MONTHS months ago" +%F) +chronic gcalcli --calendar remind delete --iamaexpert '*' +rem -ppp$MONTHS -b1 -m $START | rem2ics | chronic gcalcli --calendar remind import - |
