diff options
| author | Loïc Guégan <loic.guegan@mailbox.org> | 2024-09-17 11:12:22 +0200 |
|---|---|---|
| committer | Loïc Guégan <loic.guegan@mailbox.org> | 2024-09-17 11:12:22 +0200 |
| commit | 1b97acaa87a8e8740381573bd3d994344b008043 (patch) | |
| tree | a4d65540763f35311a478311e444898c0cdf10f3 | |
| parent | fc2d09d5aef9e89ff09137b64b7001e5bf0babaf (diff) | |
Minor changes
| -rw-r--r-- | tropical/db.py | 14 | ||||
| -rw-r--r-- | tropical/env.py | 16 | ||||
| -rwxr-xr-x | tropical/tropical.py | 1 |
3 files changed, 30 insertions, 1 deletions
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) |
