From 1b97acaa87a8e8740381573bd3d994344b008043 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Gu=C3=A9gan?= <loic.guegan@mailbox.org>
Date: Tue, 17 Sep 2024 11:12:22 +0200
Subject: [PATCH] Minor changes

---
 tropical/db.py       | 14 ++++++++++++++
 tropical/env.py      | 16 +++++++++++++++-
 tropical/tropical.py |  1 +
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/tropical/db.py b/tropical/db.py
index 431fce8..372f440 100644
--- a/tropical/db.py
+++ b/tropical/db.py
@@ -1,11 +1,21 @@
 import sqlite3, time, socket
 
+def rowFactory(cursor, row):
+    """
+    Create dictionary for each sqlite row
+    """
+    d = {}
+    for idx, col in enumerate(cursor.description):
+        d[col[0]] = row[idx]
+    return d
+
 class CalDB:
     __DBVERSION__="1"
     
     def __init__(self, dbPath):
         self.path=dbPath
         self.con=sqlite3.connect(dbPath)
+        self.con.row_factory = rowFactory
         self.cur=self.con.cursor()
 
         # Init database
@@ -34,3 +44,7 @@ class CalDB:
         Event format: { name: str, calendar: int, desc: str, start: float, end: float, repeat: str, frequency: int }
         """
         pass
+
+    def listEvents(self):
+        res=self.cur.execute("SELECT * FROM events")
+        return res.fetchall()
diff --git a/tropical/env.py b/tropical/env.py
index e2484fd..59ac509 100644
--- a/tropical/env.py
+++ b/tropical/env.py
@@ -3,6 +3,8 @@ from pathlib import Path
 from db import CalDB
 import configparser
 from enum import Enum
+from datetime import date, timedelta
+import datetime, time
 
 class EvtRepeat(Enum):
     DAYLY = 1
@@ -42,5 +44,17 @@ class Env:
         self.config["global"]={"new":True}
         with open(self.confFile,"w") as f:
             self.config.write(f)
-    
+
+    def listEventsOn(self, yy, mm, dd):
+        offset=24*3600-1
+        d=datetime.date(yy,mm,dd)
+        start=int(time.mktime(d.timetuple()))
+        end=start+offset
+        events=list()
+        for e in self.db.listEvents():
+            if e["start"] >=start and e["start"] <= end:
+                events.append(e)
+            # TODO: Account for repeat
+
+
     
diff --git a/tropical/tropical.py b/tropical/tropical.py
index 774cf18..13281b3 100755
--- a/tropical/tropical.py
+++ b/tropical/tropical.py
@@ -14,6 +14,7 @@ __VERSION__ = "0.1"
 
 if __name__ == '__main__':
     env=Env()
+    env.listEventsOn(2024,10,1)
     calState=CalState()
     QtCalanus.StartApplication(__VERSION__,calState)