Update Makefile and service file for installing remindme_caldav

- Create new directories in /etc/
- Update the install command to include the new directories creation
This commit is contained in:
mrsu 2024-02-15 22:54:56 +00:00
parent aeb1eddbbb
commit a2a508fd31
4 changed files with 8 additions and 13 deletions

View File

@ -1,10 +1,10 @@
install: install:
sudo apt-get update && sudo apt install python3-venv -y sudo apt-get update && sudo apt install python3-venv -y
sudo mkdir /etc/remindme_caldav /etc/remindme_caldav
python3 -m venv /opt/remindme_caldav/.venv python3 -m venv /opt/remindme_caldav/.venv
cp remindme_caldav.py alert_processor.py /opt/remindme_caldav/ cp remindme_caldav.py alert_processor.py /opt/remindme_caldav/
. /opt/remindme_caldav/.venv/bin/activate && pip3 install -r requirements.txt . /opt/remindme_caldav/.venv/bin/activate && pip3 install -r requirements.txt
sudo cp remindme_caldav.service /etc/systemd/system/ sudo cp remindme_caldav.service /etc/systemd/system/
sudo mkdir /etc/remindme_caldav
sudo cp config.toml /etc/remindme_caldav/config.toml sudo cp config.toml /etc/remindme_caldav/config.toml
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable remindme_caldav.service sudo systemctl enable remindme_caldav.service

View File

@ -12,5 +12,3 @@ recipient =
jid = jid =
password = password =
recipient = recipient =
[notify-send]

View File

@ -13,7 +13,7 @@ import argparse, textwrap, logging
from alert_processor import AlertProcessor from alert_processor import AlertProcessor
log_format='[%(levelname)s] %(asctime)s %(message)s' log_format='[%(levelname)s] %(asctime)s %(message)s'
logging.basicConfig(format=log_format, level=logging.INFO) logging.basicConfig(format=log_format)
logger = logging.getLogger() logger = logging.getLogger()
def parse_args(): def parse_args():
@ -21,13 +21,12 @@ def parse_args():
parser = argparse.ArgumentParser(description="A simple calendar alerting daemon written in Python") parser = argparse.ArgumentParser(description="A simple calendar alerting daemon written in Python")
parser.add_argument('--config', type=str, help='Path to config file. Must be .toml') parser.add_argument('--config', type=str, help='Path to config file. Must be .toml')
parser.add_argument('--logfile', type=str, help='Path to logfile file. Default logfile', default = "none") parser.add_argument('--logfile', type=str, help='Path to logfile file. Default logfile', default = "none")
parser.add_argument('--loglevel', choices=['info', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], default='INFO', help='Set the logging level')
return parser.parse_args() return parser.parse_args()
def read_file(filename): def read_file(filename):
try: try:
return Path(filename).read_text() return Path(filename).read_text()
except FileNotFoundError as e: except FileNotFoundError:
logger.error("Error: The specified file does not exist.") logger.error("Error: The specified file does not exist.")
sys.exit(1) sys.exit(1)
@ -35,7 +34,7 @@ def parse_toml(content):
try: try:
config = toml.loads(content) config = toml.loads(content)
return config return config
except Exception as e: except Exception:
logger.error("Error: Failed to parse TOML file.") logger.error("Error: Failed to parse TOML file.")
sys.exit(1) sys.exit(1)
@ -229,7 +228,7 @@ class CalendarParser:
} }
try: try:
new_hash = calculate_event_hash(event_dict) # Calculate the hash of the event dictionary new_hash = calculate_event_hash(event_dict) # Calculate the hash of the event dictionary
except Exception as e: except Exception:
raise RuntimeError("Error calculating event hash") raise RuntimeError("Error calculating event hash")
event_dict["hash"] = new_hash # Store the hash in the event dictionary event_dict["hash"] = new_hash # Store the hash in the event dictionary
return event_dict return event_dict
@ -240,7 +239,7 @@ class CalendarParser:
""" """
try: try:
return Calendar.from_ical(cal_str) return Calendar.from_ical(cal_str)
except Exception as e: except Exception:
raise RuntimeError("Error parsing calendar.") raise RuntimeError("Error parsing calendar.")
def process_event(self, event): def process_event(self, event):
@ -275,7 +274,7 @@ class CalendarParser:
return dtstart.replace(tzinfo=pytz.UTC) return dtstart.replace(tzinfo=pytz.UTC)
else: else:
return dt.datetime.combine(dtstart, dt.time.min).replace(tzinfo=pytz.UTC) return dt.datetime.combine(dtstart, dt.time.min).replace(tzinfo=pytz.UTC)
except Exception as e: except Exception:
raise RuntimeError("Error converting dtstart to datetime.") raise RuntimeError("Error converting dtstart to datetime.")
def remove_exdates(self, exdates, recur_dates): def remove_exdates(self, exdates, recur_dates):
@ -289,7 +288,7 @@ class CalendarParser:
else: else:
exdates = [exdates.dts[0].dt.replace(tzinfo=pytz.UTC)] exdates = [exdates.dts[0].dt.replace(tzinfo=pytz.UTC)]
return [i for i in recur_dates if i not in exdates] return [i for i in recur_dates if i not in exdates]
except Exception as e: except Exception:
raise RuntimeError("Error processing exdates.") raise RuntimeError("Error processing exdates.")
else: else:
return recur_dates return recur_dates
@ -340,7 +339,6 @@ def process_alert(current_time, next_alert, next_event, event, config):
except Exception as e: except Exception as e:
raise RuntimeError("Error sending alert for event.") raise RuntimeError("Error sending alert for event.")
#processor.send_xmpp(event, next_alert, next_event) #processor.send_xmpp(event, next_alert, next_event)
with open("alert_history", 'a') as f: with open("alert_history", 'a') as f:
f.write(str(event)) f.write(str(event))
return return

View File

@ -5,7 +5,6 @@ StartLimitIntervalSec=0
[Service] [Service]
Type=simple Type=simple
Restart=always
RestartSec=1 RestartSec=1
User=root User=root
ExecStart=/opt/remindme_caldav/.venv/bin/python3 -u /opt/remindme_caldav/remindme_caldav.py --config /etc/remindme_caldav/config.toml --logfile /opt/remindme_caldav/log ExecStart=/opt/remindme_caldav/.venv/bin/python3 -u /opt/remindme_caldav/remindme_caldav.py --config /etc/remindme_caldav/config.toml --logfile /opt/remindme_caldav/log