39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
'''
|
|
Storage module
|
|
'''
|
|
from models.house import House
|
|
import sqlite3
|
|
|
|
|
|
|
|
class Storage():
|
|
def __init__(self, path="storage.db"):
|
|
self.db = sqlite3.connect(path, check_same_thread=False)
|
|
self.cursor = self.db.cursor()
|
|
housestable = """CREATE TABLE IF NOT EXISTS houses (
|
|
id integer PRIMARY KEY,
|
|
name text NOT NULL,
|
|
image text NOT NULL,
|
|
url text,
|
|
checked integer
|
|
);"""
|
|
self.db.execute(housestable)
|
|
self.db.commit()
|
|
|
|
def close(self):
|
|
self.db.close()
|
|
|
|
def AddHouse(self, house : House):
|
|
self.db.execute(f"""
|
|
INSERT INTO houses(name, image, url, checked)
|
|
VALUES
|
|
('{house.name}', '{house.image}', '{str(house.url)}', {int(house.checked)})
|
|
""")
|
|
self.db.commit()
|
|
|
|
def GetHouses(self):
|
|
hs = self.cursor.execute("select * from houses").fetchall()
|
|
ret = []
|
|
for h in hs:
|
|
ret.append(House(id=h[0], url=h[3], name=h[1], image=h[2], checked=h[4]))
|
|
return ret |