From 9237f6cec7ff7bb0dee56029358b4b096e535f64 Mon Sep 17 00:00:00 2001 From: morkolai <nikolai-mork@live.no> Date: Fri, 28 Feb 2020 13:58:43 +0100 Subject: [PATCH] =?UTF-8?q?#5=20Laget=20mulighet=20for=20get=5Fcodebook=20?= =?UTF-8?q?til=20=C3=A5=20b=C3=A5de=20hente=20stor=20og=20liten=20kodebok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soitool/database.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/soitool/database.py b/soitool/database.py index f7131aa..3aeeb76 100644 --- a/soitool/database.py +++ b/soitool/database.py @@ -120,25 +120,33 @@ class Database(): return categories - def get_small_codebook(self): + def get_codebook(self, small=False): """ - Retrive the entries belonging to the small codebook. + Retrive the entries belonging to the small codebook or big codebook. + + Parameters + ---------- + small : Bool + Full or smal codebook to be returned Returns ------- - Lsit of dicts + codebook : list (of dicts) [{'word': str, 'type': str, 'category': str, 'code': str}] - - """ - stmt = 'SELECT * FROM CodeBook WHERE Type = ?' - queried = self.conn.execute(stmt, (1,)).fetchall() + # Get either small or whole codebook + stmt = 'SELECT * FROM CodeBook' + if (small): + stmt = stmt + ' WHERE Type = ?' + queried = self.conn.execute(stmt, (1,)).fetchall() + else: + queried = self.conn.execute(stmt).fetchall() - small_codebook = [] + codebook = [] for entry in queried: - small_codebook.append({'word': entry['Word'], - 'category': entry['Category'], - 'type': entry['Type'], - 'code': entry['Code']}) + codebook.append({'word': entry['Word'], + 'category': entry['Category'], + 'type': entry['Type'], + 'code': entry['Code']}) - return small_codebook + return codebook -- GitLab