Beispiel #1
0
def load_data():
    try:
        messages = db.getDb("donutsdb.json")
    except Exception as err:
        print("Error while hadnling database: {0}".format(err))
        raise

    return messages
Beispiel #2
0
def get_user(username):
    database = db.getDb(os.getcwd() + '/db/users.json')
    query = database.getBy({'username': username})
    if not query:
        return None
    else:
        user_data = query[0]
        return User(user_data['username'], user_data["password"])
Beispiel #3
0
def login(username, password):
    database = db.getDb(os.getcwd() + '/db/users.json')
    query = database.getBy({'username': username})
    if not query:
        return None
    else:
        user_data = query[0]
        if check_password_hash(user_data['password'], password):
            return User(user_data['username'], user_data["password"])
        else:
            return None
Beispiel #4
0
def create_user(username, password):
    database = db.getDb(os.getcwd() + '/db/users.json')
    if not database.getBy({'username': username}):
        password_hash = generate_password_hash(password)
        user_id = database.add({
            'username': username,
            'password': password_hash
        })
        query = database.getBy({'id': user_id})
        user_data = query[0]
        return User(user_data['username'], user_data["password"])
    else:
        return None
Beispiel #5
0
 def __init__(self) -> None:
     self._db = db.getDb(DB_PATH)
Beispiel #6
0
from pysondb import db
import json
from myBoat import myBoat
myBoat = myBoat()
XCoord = 1.0
YCoord = 5.0
Angle = 0.5 * math.pi
timeData = []
velocityData = []
headingData = []
samplePeriod = 0.25
count = 0
DistanceToTarget = 5
DistanceToTargetY = 0.1
FarDistanceModeSpeed = 5
a = db.getDb("db.json")


def control_loop(num):
    n = 0
    startTime = time.time()
    checkValue = 1
    while 1 > 0:

        if (time.time() > startTime):
            startTime += 0.01
            global count
            global headingData
            global velocityData
            global timeData
            headingData.append(myBoat.getHeading())
Beispiel #7
0
def delete_message(message: object):
    id = message["id"]
    print(id)
    messages = db.getDb("donutsdb.json")
    messages.updateById(str(id), {"used": True})
Beispiel #8
0
from pysondb import db

a = db.getDb("registry.json")
while True:
  name=input("Enter Name:")
  age=input("Enter type:")
  score=input("Enter Score:")
  a.add({"name":name,"type":age,"score":score})
  c=input("add more(y,n)")
  if c=="n":
    print(a.getAll())
    break
  
Beispiel #9
0
from pysondb import db
from tabulate import tabulate
import sys
import json
from src import printcolors as pc

categories = db.getDb("categories.json")
expenses = db.getDb("expenses.json")
incomes = db.getDb("incomes.json")


def calculate_total_cost(_budget_query, _expenses_query, _id):
    budget = categories.getBy(_budget_query)
    for i in budget:
        budget = i["budget_total"]
    total_expenses = expenses.getBy(_expenses_query)
    amounts = [i.get("amount", None) for i in total_expenses]
    result = sum(map(int, amounts))
    cost_total = int(result)
    rest = int(budget) - int(result)
    if result == 0:
        cost_total = 0
    categories.updateById(_id, {"rest": rest})
    categories.updateById(_id, {"cost_total": cost_total})


def define_budget(budgeting):
    if budgeting == "1":
        rental_budget = input("How much is your rental budget?: $")
        categories.updateById(4274828660, {"budget_total": rental_budget})
    elif budgeting == "2":
Beispiel #10
0
from pysondb import db
a = db.getDb("test.json")


def addtests():

    x = a.add({"name": "test"})


def gettests():
    x = len(a.get(1))


def wrongaddtest():
    y = a.add({"namme": "sd"})
    assert y == "False"


def updatetest():
    a.update({"name": "test"}, {"name": "tests"})
    x = a.get()[0]['name']
    assert x == "tests"


def deletetest():
    x = a.get()[0]['id']
    a.deleteById(x)
    y = a.get()


if __name__ == "__main__":
Beispiel #11
0
 def __init__(self):
     self.data_batch = []
     self.is_running = True
     self.batch_sync_completed = False
     self.db_connection = db.getDb("user_prox_chat_db.json")
Beispiel #12
0
def save_msg(username, msg):
    time = datetime.now()
    timestamp = (time - datetime(1970, 1, 1)).total_seconds()
    database = db.getDb(os.getcwd() + '/db/messages.json')
    database.add({'username': username, 'msg': msg, 'timestamp': timestamp})
    return True
Beispiel #13
0
 def __init__(self) -> None:
     self._db = db.getDb(filename=DB_PATH)