Compare commits

..

2 commits

Author SHA1 Message Date
9d7afca6a9 . 2025-11-16 10:55:55 +01:00
87a645d0fc added credentials file 2025-11-16 10:55:01 +01:00
5 changed files with 93 additions and 46 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
__pycache__
result
config.ini

8
default_config.ini Normal file
View file

@ -0,0 +1,8 @@
[calDAV]
address = localhost:5232
username = username
password = password
passwordFile = /path/to/password
[server]
port = 8000

View file

@ -33,33 +33,57 @@
nixosModules.caldavToCsv = { config, lib, ... }:
let cfg = config.services.caldavToCsv;
in {
options.NixosModule = {
enable = lib.mkEnableOption "Enable calDAVtoCSV service";
port = lib.mkOption {
type = lib.types.int;
default = 8000;
description = "Port on which calDAVtoCSV will listen";
options.calDavtoCSV = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Enable myService";
};
url = lib.mkOption {
type = lib.types.str;
description = "url of the calendar";
config = lib.mkOption {
type = lib.types.attrs;
default = {
calDAV = {
address = "localhost:5232";
username = "username";
password = "password";
passwordFile = "/path/to/password";
};
calendarUsername = lib.mkOption {
type = lib.types.str;
description = "username of the calendar account";
server = { port = 8000; };
};
calendarName = lib.mkOption {
type = lib.types.str;
description =
"name of the calendar we will fetch the todo items from";
};
calendarPasswordFile = lib.mkOption {
type = lib.types.str;
description =
"file where we need to look for password to connect, needs to be readeable by the service user";
description = "User-defined configuration for the service";
};
};
# options.NixosModule = {
# enable = lib.mkEnableOption "Enable calDAVtoCSV service";
# port = lib.mkOption {
# type = lib.types.int;
# default = 8000;
# description = "Port on which calDAVtoCSV will listen";
# };
# url = lib.mkOption {
# type = lib.types.str;
# description = "url of the calendar";
# };
# calendarUsername = lib.mkOption {
# type = lib.types.str;
# description = "username of the calendar account";
# };
# calendarName = lib.mkOption {
# type = lib.types.str;
# description =
# "name of the calendar we will fetch the todo items from";
# };
# calendarPasswordFile = lib.mkOption {
# type = lib.types.str;
# description =
# "file where we need to look for password to connect, needs to be readeable by the service user";
# };
# };
config = lib.mkIf config.myModule.enable {
environment.etc."config.ini".text = ''
${lib.toIni config.myService.config}
'';
systemd.services.calDAVtoCSV = {
description = "calDAV to CSV Service";
after = [ "network.target" ];

46
main.py
View file

@ -2,21 +2,40 @@
from flask import Flask
from caldav import DAVClient, Calendar, Principal, Todo
import configparser
# TODO:
# [ ] settings file to not have hardcoded credentials
# [x] settings file to not have hardcoded credentials
# [ ] change production credentials
# [ ] nix flake with complete module
# [ ] post behavior (simple)
# [ ] post behavior (concurrent protection)
# [ ] check if better http server availible or fastcgi better suited
#!/usr/bin/env python
def parseConfig():
config = configparser.ConfigParser()
config.read("/home/stuce/calDAVtoCSV/config.ini") # TODO: change this
global calDavAddress
global calDavUsername
global calDavPassword
global calDavCalendarName
global serverPort
calDavAddress = config.get("calDAV", "address")
calDavUsername = config.get("calDAV", "username")
calDavPassword = config.get("calDAV", "password")
calDavPasswordFile = config.get("calDAV", "passwordFile")
calDavCalendarName = config.get("calDAV", "calendarName")
serverPort = config.getint("server", "port")
def fetch_10_next_todos_as_csv() -> str:
def auth() -> Principal:
# TODO: on the final version, fetch it locally
client = DAVClient(
url="https://cal.stuce.ch", username="eInk", password="4Ftxy9rp8e$F*f"
url=calDavAddress, username=calDavUsername, password=calDavPassword
)
principal = client.principal()
return principal
@ -45,26 +64,6 @@ def put(todos, uid):
item = filter(lambda todo: todo.icalendar_component["uid"] == uid, todos)
# class SimpleHandler(BaseHTTPRequestHandler):
# def do_GET(self):
# self.send_response(200)
# self.send_header("Content-type", "text/plain")
# self.end_headers()
# response_body_str = fetch_10_next_todos_as_csv()
# response_body_utf8 = response_body_str.encode("utf8")
# self.wfile.write(response_body_utf8)
#
#
# def main(server_class=HTTPServer, port=8000):
# server_address = ("", port)
# httpd = server_class(server_address, SimpleHandler)
# httpd.serve_forever()
#
#
# if __name__ == "__main__":
# main()
app = Flask(__name__)
@ -74,4 +73,5 @@ def send_events():
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
parseConfig()
app.run(host="0.0.0.0", port=serverPort)

12
setup.py Normal file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(
name="calDAVtoCSV",
version="1.0",
# Modules to import from other scripts:
packages=find_packages(),
# Executables
scripts=["main.py"],
)