Skip to content
Snippets Groups Projects
Commit 9237f6ce authored by morkolai's avatar morkolai
Browse files

#5 Laget mulighet for get_codebook til å både hente stor og liten kodebok

parent 8f3696d9
No related branches found
No related tags found
1 merge request!10Database setup
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment