def led(self, data, port):
     collection = create_connection_to_database()
     collection = collection.connect_to_db()
     czas = datetime.datetime.now()
     czas = czas.strftime("%Y-%m-%d %H:%M:%S")
     dane_model_led = {'data': czas, 'wartosc': str(port), 'czujnik': 'led'}
     result = collection.insert_many([dane_model_led])
Exemple #2
0
def get_last_n_days(days, czujnik):
    czas = (datetime.now() - timedelta(days))
    czas = czas.strftime("%Y-%m-%d %H:%M:%S")
    client = create_connection_to_database()
    db = client.connect_to_db()
    records = db.find({'data': {"$gte": czas}, 'czujnik': czujnik}, {'_id': 0})
    return records
Exemple #3
0
def get_led_port():
    client = create_connection_to_database()
    db = client.connect_to_db()
    records = db.find({'czujnik': 'led'}).sort('data', -1)
    client.disconnect_from_db()
    list_of_led_ports = [x for x in records]
    return list_of_led_ports[0]['wartosc'] if len(
        list_of_led_ports) != 0 else 'None'
def decrypt_password(main_haslo):
    collection = create_connection_to_database()
    collection = collection.connect_to_db_password()
    password = collection.find_one({'haslo': {"$exists": True}})
    passwd = password['haslo']
    klucz = get_key_from_file(main_haslo)
    fernet = Fernet(klucz)
    decr = fernet.decrypt(passwd).decode()
    return decr
def dehashowanie_hasla(haslo):
    collection = create_connection_to_database()
    collection = collection.connect_to_db_password()
    password = collection.find_one({'haslo_glowne': {"$exists": True}})
    passwd = password['haslo_glowne']
    random = passwd[32:]
    obecne = passwd[:32]
    zahashowane_haslo = hashlib.pbkdf2_hmac("sha256", haslo.encode('utf-8'),
                                            random, 100000)
    assert zahashowane_haslo == obecne
 def liquid_level_data_processing(self, data):
     data = data[0]
     collection = create_connection_to_database()
     collection = collection.connect_to_db()
     czas = datetime.datetime.now()
     czas = czas.strftime("%Y-%m-%d %H:%M:%S")
     dane_model_poziom_cieczy = {
         'data': czas,
         'wartosc': int(data),
         'czujnik': 'ciecz'
     }
     result = collection.insert_many([dane_model_poziom_cieczy])
Exemple #7
0
def set_account(main_haslo):
    print(
        "Brak ustawionego konta e-mail. Prosze utawić konto porzed pierwszym użyciem programu"
    )
    email = input("Podaj email: ")
    paswd = getpass.getpass('Podaj haslo do konta email:')
    save_key_to_file(main_haslo)
    collection = create_connection_to_database()
    collection = collection.connect_to_db_password()
    collection.insert_one({
        'email': email,
        'haslo': encrypt_password(paswd, main_haslo)
    })
    print("Konto email zostało ustawione")
 def add_wilgotnosc_and_temp_to_db(self, wilgotnosc, temperatura, pyl):
     collection = create_connection_to_database()
     collection = collection.connect_to_db()
     czas = datetime.datetime.now()
     czas = czas.strftime("%Y-%m-%d %H:%M:%S")
     dane_model_temperatura = {
         'data': czas,
         'wartosc': int(temperatura),
         'czujnik': 'temperatura'
     }
     dane_model_wilgotnosc = {
         'data': czas,
         'wartosc': int(wilgotnosc),
         'czujnik': 'wilgotnosc'
     }
     dane_model_pyl = {
         'data': czas,
         'wartosc': float(pyl),
         'czujnik': 'pyl'
     }
     result = collection.insert_many(
         [dane_model_temperatura, dane_model_wilgotnosc, dane_model_pyl])
def add_password_to_mongo_db(haslo):
    collection = create_connection_to_database()
    collection = collection.connect_to_db_password()
    collection.insert_one({'haslo_glowne': haslo})
Exemple #10
0
def check_main_password():
    collection = create_connection_to_database()
    collection = collection.connect_to_db_password()
    password = collection.find({"haslo_glowne": {"$exists": True}}).limit(1)
    return False if password.count() == 0 else True
Exemple #11
0
def check_password():
    collection = create_connection_to_database()
    collection = collection.connect_to_db_password()
    password = collection.find()
    return False if password == None else True