Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

My small agenda project

I wrote a small program for myself to send me an email of the daily agenda. It uses python library caldav to get the events. It was for this project I had to write the previous post's solution.

It writes a small html output, and then I have a few scripts I use to turn it into an email to myself.

#!/usr/bin/env python3
# File: server3.py
# Startdate: 2023-05-17 15:47:40
# Purpose: script on server3 that generates email message content
import sys, datetime, os
sys.path.append("/home/agenda/agenda")
import agenda
url = "https://server3.ipa.internal.com/radicale/"
username = "bgstack15"
password = "plaintextpw"
thisdate = datetime.date.today()
try:
   thisdate = os.environ.get("AGENDA_DATE",datetime.date.today())
except:
   pass
print(f"Using date {thisdate}",file=sys.stderr)
print(agenda.summarize(thisdate,url=url,username=username,password=password),end="")

The above python script gets called by a shell script:

#!/bin/sh
# startdate: 2023-05-17-4 15:58
# Purpose: job for emailing daily agenda, for adding to cron
export AGENDA_DATE
results="$( /home/agenda/server3.py )"
test -z "${AGENDA_DATE}" && AGENDA_DATE="$( date "+%F" )"
subject="Daily agenda for ${AGENDA_DATE}"
if test -z "${results}" ;
then
   results="nothing on the agenda today"
   subject="nothing on agenda"
fi
echo "${results}" | mailx -s "$( printf '%s\n%s' "${subject}" "Content-Type: text/html" )" "bgstack15@gmail.com"

And then I threw this into cron:

# File: /etc/cron.d/85_agenda_email_cron
58  6  *  *  *  agenda   sh /home/agenda/server3.sh 1>>/var/server3/shares/public/Support/Systems/server3/var/log/agenda_log 2>&1

Sample html output (let's see if this works in my markdown file used in my SSG):

Online

All day: Pay water bill

Work

8:00am: Work

Main

11:30am: Lunch
2:00pm: Call Nick
5:00pm: remind Joe about AoE2

Comments