Initial commit with current state
This commit is contained in:
commit
ca6bdb8890
7 changed files with 294 additions and 0 deletions
77
main.py
Executable file
77
main.py
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from flask import Flask
|
||||
from caldav import DAVClient, Calendar, Principal, Todo
|
||||
import configparser
|
||||
|
||||
|
||||
# TODO:
|
||||
# [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=calDavAddress, username=calDavUsername, password=calDavPassword
|
||||
)
|
||||
principal = client.principal()
|
||||
return principal
|
||||
|
||||
def get_calendar(principal: Principal) -> Calendar:
|
||||
calendar = principal.calendar(name="Ouais le ménage")
|
||||
return calendar
|
||||
|
||||
def todos_to_csv(todos: list[Todo]) -> str:
|
||||
result = "".join(
|
||||
f"{todo.icalendar_component['uid']},{todo.icalendar_component['summary']}\n"
|
||||
for todo in todos
|
||||
)
|
||||
return result
|
||||
|
||||
principal = auth()
|
||||
calendar = get_calendar(principal)
|
||||
|
||||
sorted_todos = calendar.todos(sort_keys=("due"))
|
||||
cut_todos = sorted_todos[:10]
|
||||
csv = todos_to_csv(cut_todos)
|
||||
return csv
|
||||
|
||||
|
||||
def put(todos, uid):
|
||||
item = filter(lambda todo: todo.icalendar_component["uid"] == uid, todos)
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def send_events():
|
||||
return fetch_10_next_todos_as_csv()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parseConfig()
|
||||
app.run(host="0.0.0.0", port=serverPort)
|
||||
Loading…
Add table
Add a link
Reference in a new issue