5s
This commit is contained in:
+31
-6
@@ -1,7 +1,32 @@
|
||||
# Образец для расширения!
|
||||
from tinydb import TinyDB, Query
|
||||
import os
|
||||
import json
|
||||
|
||||
from tinydb import TinyDB
|
||||
|
||||
db = TinyDB("db.json")
|
||||
|
||||
db.insert({"name": "Alex", "age": 25})
|
||||
class DB:
|
||||
def __init__(self):
|
||||
db_path = "datas"
|
||||
if not os.path.exists(db_path):
|
||||
os.makedirs(os.path.dirname(db_path), exist_ok=True)
|
||||
json.dump({}, open(db_path+"/db.json", "w", encoding="utf-8"))
|
||||
self.db = TinyDB(db_path+"/db.json")
|
||||
self.File = Query()
|
||||
|
||||
def add(self, data_add):
|
||||
self.db.insert(data_add)
|
||||
|
||||
def get_all(self):
|
||||
return self.db.all()
|
||||
|
||||
def get_search(self, ratings, tags):
|
||||
results = self.db.search(
|
||||
self.File.rating.one_of(self.ratings) &
|
||||
self.File.tags.any(self.tags)
|
||||
)
|
||||
return results
|
||||
|
||||
def get_unknow(self):
|
||||
results = self.db.search(self.File.tags == [])
|
||||
return results
|
||||
|
||||
def edit_data(self, id_file, edit_data):
|
||||
self.db.update(self.edit_data, self.File.md5 == self.id_file)
|
||||
Reference in New Issue
Block a user