added credentials file

This commit is contained in:
Stuce 2025-11-16 10:55:01 +01:00
parent 3a2241e434
commit 87a645d0fc
3 changed files with 82 additions and 46 deletions

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)