Compare commits
2 commits
3a2241e434
...
9d7afca6a9
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d7afca6a9 | |||
| 87a645d0fc |
5 changed files with 93 additions and 46 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
__pycache__
|
||||||
|
result
|
||||||
|
config.ini
|
||||||
8
default_config.ini
Normal file
8
default_config.ini
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[calDAV]
|
||||||
|
address = localhost:5232
|
||||||
|
username = username
|
||||||
|
password = password
|
||||||
|
passwordFile = /path/to/password
|
||||||
|
[server]
|
||||||
|
port = 8000
|
||||||
|
|
||||||
66
flake.nix
66
flake.nix
|
|
@ -33,33 +33,57 @@
|
||||||
nixosModules.caldavToCsv = { config, lib, ... }:
|
nixosModules.caldavToCsv = { config, lib, ... }:
|
||||||
let cfg = config.services.caldavToCsv;
|
let cfg = config.services.caldavToCsv;
|
||||||
in {
|
in {
|
||||||
options.NixosModule = {
|
options.calDavtoCSV = {
|
||||||
enable = lib.mkEnableOption "Enable calDAVtoCSV service";
|
enable = lib.mkOption {
|
||||||
port = lib.mkOption {
|
type = lib.types.bool;
|
||||||
type = lib.types.int;
|
default = false;
|
||||||
default = 8000;
|
description = "Enable myService";
|
||||||
description = "Port on which calDAVtoCSV will listen";
|
|
||||||
};
|
};
|
||||||
url = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
config = lib.mkOption {
|
||||||
description = "url of the calendar";
|
type = lib.types.attrs;
|
||||||
|
default = {
|
||||||
|
calDAV = {
|
||||||
|
address = "localhost:5232";
|
||||||
|
username = "username";
|
||||||
|
password = "password";
|
||||||
|
passwordFile = "/path/to/password";
|
||||||
};
|
};
|
||||||
calendarUsername = lib.mkOption {
|
server = { port = 8000; };
|
||||||
type = lib.types.str;
|
|
||||||
description = "username of the calendar account";
|
|
||||||
};
|
};
|
||||||
calendarName = lib.mkOption {
|
description = "User-defined configuration for the service";
|
||||||
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";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
# 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 {
|
config = lib.mkIf config.myModule.enable {
|
||||||
|
environment.etc."config.ini".text = ''
|
||||||
|
${lib.toIni config.myService.config}
|
||||||
|
'';
|
||||||
systemd.services.calDAVtoCSV = {
|
systemd.services.calDAVtoCSV = {
|
||||||
description = "calDAV to CSV Service";
|
description = "calDAV to CSV Service";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
|
|
|
||||||
46
main.py
46
main.py
|
|
@ -2,21 +2,40 @@
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from caldav import DAVClient, Calendar, Principal, Todo
|
from caldav import DAVClient, Calendar, Principal, Todo
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# [ ] settings file to not have hardcoded credentials
|
# [x] settings file to not have hardcoded credentials
|
||||||
# [ ] change production credentials
|
# [ ] change production credentials
|
||||||
# [ ] nix flake with complete module
|
# [ ] nix flake with complete module
|
||||||
# [ ] post behavior (simple)
|
# [ ] post behavior (simple)
|
||||||
# [ ] post behavior (concurrent protection)
|
# [ ] post behavior (concurrent protection)
|
||||||
# [ ] check if better http server availible or fastcgi better suited
|
# [ ] check if better http server availible or fastcgi better suited
|
||||||
#!/usr/bin/env python
|
#!/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 fetch_10_next_todos_as_csv() -> str:
|
||||||
def auth() -> Principal:
|
def auth() -> Principal:
|
||||||
# TODO: on the final version, fetch it locally
|
# TODO: on the final version, fetch it locally
|
||||||
client = DAVClient(
|
client = DAVClient(
|
||||||
url="https://cal.stuce.ch", username="eInk", password="4Ftxy9rp8e$F*f"
|
url=calDavAddress, username=calDavUsername, password=calDavPassword
|
||||||
)
|
)
|
||||||
principal = client.principal()
|
principal = client.principal()
|
||||||
return principal
|
return principal
|
||||||
|
|
@ -45,26 +64,6 @@ def put(todos, uid):
|
||||||
item = filter(lambda todo: todo.icalendar_component["uid"] == uid, todos)
|
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__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -74,4 +73,5 @@ def send_events():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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
12
setup.py
Normal 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"],
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue