Minor changes

This commit is contained in:
Loïc Guégan 2024-09-17 11:12:22 +02:00
parent fc2d09d5ae
commit 1b97acaa87
3 changed files with 30 additions and 1 deletions

View file

@ -1,11 +1,21 @@
import sqlite3, time, socket 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: class CalDB:
__DBVERSION__="1" __DBVERSION__="1"
def __init__(self, dbPath): def __init__(self, dbPath):
self.path=dbPath self.path=dbPath
self.con=sqlite3.connect(dbPath) self.con=sqlite3.connect(dbPath)
self.con.row_factory = rowFactory
self.cur=self.con.cursor() self.cur=self.con.cursor()
# Init database # Init database
@ -34,3 +44,7 @@ class CalDB:
Event format: { name: str, calendar: int, desc: str, start: float, end: float, repeat: str, frequency: int } Event format: { name: str, calendar: int, desc: str, start: float, end: float, repeat: str, frequency: int }
""" """
pass pass
def listEvents(self):
res=self.cur.execute("SELECT * FROM events")
return res.fetchall()

View file

@ -3,6 +3,8 @@ from pathlib import Path
from db import CalDB from db import CalDB
import configparser import configparser
from enum import Enum from enum import Enum
from datetime import date, timedelta
import datetime, time
class EvtRepeat(Enum): class EvtRepeat(Enum):
DAYLY = 1 DAYLY = 1
@ -42,5 +44,17 @@ class Env:
self.config["global"]={"new":True} self.config["global"]={"new":True}
with open(self.confFile,"w") as f: with open(self.confFile,"w") as f:
self.config.write(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

View file

@ -14,6 +14,7 @@ __VERSION__ = "0.1"
if __name__ == '__main__': if __name__ == '__main__':
env=Env() env=Env()
env.listEventsOn(2024,10,1)
calState=CalState() calState=CalState()
QtCalanus.StartApplication(__VERSION__,calState) QtCalanus.StartApplication(__VERSION__,calState)