2023-05-16 16:33:36 -04:00
|
|
|
from tinydb import TinyDB, Query
|
|
|
|
from tinydb.operations import set, delete
|
|
|
|
|
|
|
|
class Database():
|
|
|
|
def __init__(self):
|
|
|
|
self.db = TinyDB("database.json", indent=4)
|
|
|
|
self.query = Query()
|
|
|
|
self.cookies_table = self.db.table("cookies")
|
|
|
|
self.viewing_table = self.db.table("viewing")
|
|
|
|
self.sites_table = self.db.table("sites")
|
|
|
|
|
|
|
|
def get_viewing_data(self, url:str ):
|
|
|
|
return (self.viewing_table.get(self.query.url == url))
|
2023-05-31 09:28:47 -04:00
|
|
|
|
|
|
|
def set_viewing_data(self, url:str, viewing_data: dict):
|
|
|
|
self.viewing_table.update(set(url, value), self.query.url == url)
|
|
|
|
|
|
|
|
def add_viewing_data(self, viewing_data):
|
|
|
|
self.viewing_table.insert(viewing_data)
|
2023-05-16 16:33:36 -04:00
|
|
|
|
|
|
|
def get_sites(self):
|
|
|
|
return (self.sites_table.all())
|
|
|
|
|
|
|
|
def get_site_by_id(self, id: int):
|
|
|
|
return (self.sites_table.get(self.query.id == id))
|
|
|
|
|
|
|
|
def get_sites_table_len(self):
|
|
|
|
return (len(self.sites_table.all()))
|
|
|
|
|
|
|
|
def get_cookies_table_len(self):
|
|
|
|
return (len(self.cookies_table.all()))
|
|
|
|
|
|
|
|
def add_cookies(self, arg: dict):
|
|
|
|
self.cookies_table.insert(arg)
|
|
|
|
|
|
|
|
def get_cookies(self):
|
|
|
|
return (self.cookies_table.get(self.query.id == "0"))
|
|
|
|
|
|
|
|
def get_last_site_id(self):
|
|
|
|
cookies = self.get_cookies()
|
|
|
|
last_site_id = cookies.get("last_site")
|
|
|
|
return (last_site_id)
|
|
|
|
|
|
|
|
def get_last_site(self):
|
|
|
|
last_site_id = self.get_last_site_id()
|
|
|
|
last_site = self.get_site_by_id(last_site_id)
|
|
|
|
return (last_site)
|
|
|
|
|
|
|
|
def get_last_path(self):
|
|
|
|
cookies = self.get_cookies()
|
|
|
|
last_path = cookies.get("last_path")
|
|
|
|
return (last_path)
|
|
|
|
|
2023-05-29 13:23:39 -04:00
|
|
|
def get_last_cursor_pos(self):
|
|
|
|
cookies = self.get_cookies()
|
|
|
|
last_path = cookies.get("last_cursor_pos")
|
|
|
|
return (last_path)
|
|
|
|
|
2023-05-16 16:33:36 -04:00
|
|
|
def set_last_site(self, value):
|
|
|
|
self.cookies_table.update(set("last_site", value), self.query.id == "0")
|
|
|
|
|
|
|
|
def set_last_path(self, value):
|
|
|
|
self.cookies_table.update(set("last_path", value), self.query.id == "0")
|
|
|
|
|
2023-05-29 13:23:39 -04:00
|
|
|
def set_last_cursor_pos(self, value):
|
|
|
|
self.cookies_table.update(set("last_cursor_pos", value), self.query.id == "0")
|
|
|
|
|
2023-05-16 16:33:36 -04:00
|
|
|
def add_site(self, site):
|
|
|
|
self.sites_table.insert(site)
|