Compare commits
No commits in common. "9d7afca6a9ca01460b4a3663ab369a8cea04a588" and "3a2241e434a245eee0766147af3db6690c8e1e67" have entirely different histories.
9d7afca6a9
...
3a2241e434
5 changed files with 46 additions and 93 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,3 +0,0 @@
|
||||||
__pycache__
|
|
||||||
result
|
|
||||||
config.ini
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
[calDAV]
|
|
||||||
address = localhost:5232
|
|
||||||
username = username
|
|
||||||
password = password
|
|
||||||
passwordFile = /path/to/password
|
|
||||||
[server]
|
|
||||||
port = 8000
|
|
||||||
|
|
||||||
70
flake.nix
70
flake.nix
|
|
@ -33,57 +33,33 @@
|
||||||
nixosModules.caldavToCsv = { config, lib, ... }:
|
nixosModules.caldavToCsv = { config, lib, ... }:
|
||||||
let cfg = config.services.caldavToCsv;
|
let cfg = config.services.caldavToCsv;
|
||||||
in {
|
in {
|
||||||
options.calDavtoCSV = {
|
options.NixosModule = {
|
||||||
enable = lib.mkOption {
|
enable = lib.mkEnableOption "Enable calDAVtoCSV service";
|
||||||
type = lib.types.bool;
|
port = lib.mkOption {
|
||||||
default = false;
|
type = lib.types.int;
|
||||||
description = "Enable myService";
|
default = 8000;
|
||||||
|
description = "Port on which calDAVtoCSV will listen";
|
||||||
};
|
};
|
||||||
|
url = lib.mkOption {
|
||||||
config = lib.mkOption {
|
type = lib.types.str;
|
||||||
type = lib.types.attrs;
|
description = "url of the calendar";
|
||||||
default = {
|
};
|
||||||
calDAV = {
|
calendarUsername = lib.mkOption {
|
||||||
address = "localhost:5232";
|
type = lib.types.str;
|
||||||
username = "username";
|
description = "username of the calendar account";
|
||||||
password = "password";
|
};
|
||||||
passwordFile = "/path/to/password";
|
calendarName = lib.mkOption {
|
||||||
};
|
type = lib.types.str;
|
||||||
server = { port = 8000; };
|
description =
|
||||||
};
|
"name of the calendar we will fetch the todo items from";
|
||||||
description = "User-defined configuration for the service";
|
};
|
||||||
|
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,40 +2,21 @@
|
||||||
|
|
||||||
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:
|
||||||
# [x] settings file to not have hardcoded credentials
|
# [ ] 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=calDavAddress, username=calDavUsername, password=calDavPassword
|
url="https://cal.stuce.ch", username="eInk", password="4Ftxy9rp8e$F*f"
|
||||||
)
|
)
|
||||||
principal = client.principal()
|
principal = client.principal()
|
||||||
return principal
|
return principal
|
||||||
|
|
@ -64,6 +45,26 @@ 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__)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -73,5 +74,4 @@ def send_events():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parseConfig()
|
app.run(host="0.0.0.0", port=8080)
|
||||||
app.run(host="0.0.0.0", port=serverPort)
|
|
||||||
|
|
|
||||||
12
setup.py
12
setup.py
|
|
@ -1,12 +0,0 @@
|
||||||
#!/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