From 8c1679382f3e4a5da01d54b473ecf61cad75bc41 Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Sat, 4 Dec 2021 17:14:49 +0530 Subject: [PATCH] initial sqlite integration --- .gitignore | 1 + plugin.py | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e69de29..600d2d3 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/plugin.py b/plugin.py index bdceed9..8c98926 100644 --- a/plugin.py +++ b/plugin.py @@ -38,12 +38,46 @@ except ImportError: # without the i18n module _ = lambda x: x +import os +import sqlite3 + +class SqliteDoselogsDB(object): + def __init__(self, filename): + self.db = {} + self.filename = filename + + def close(self): + self.db.close() + + def _getDb(self): + filename = os.path.basename(self.__class__.__name__) + if filename in self.db: + return self.db[filename] + if os.path.exists(filename): + db = sqlite3.connect(filename, check_same_thread=False) + self.db[filename] = db + return db + db = sqlite3.connect(filename, check_same_thread=False) + self.db[filename] = db + cursor = db.cursor() + cursor.execute("""CREATE TABLE doselogs ( + id INTEGER PRIMARY KEY, + username TEXT, + nick TEXT, + timezone TEXT, + amount TEXT, + drug TEXT, + roa TEXT, + timestamp TEXT + ) + + """) + class DoseLogs(callbacks.Plugin): """Log and annotate your doses""" threaded = True - Class = DoseLogs