Example #1
0
def cr_db2(path, name, last_name, passwd):

    datecr_tuple = datetime.timetuple(datetime.today())
    datecr = strftime('%d.%m.%Y_%X',
                      datecr_tuple)  #получаю дату в нужном форматке

    passwd_sha256 = sha256(bytes(
        passwd, encoding='utf-8')).hexdigest()  # шифрую пароль
    conn = sqlite3.connect(path)
    cursor = conn.cursor()

    id = 0
    try:
        id = (cursor.execute("SELECT max(id) FROM Users").fetchall()[0])[0] + 1
    except:
        id = 1

    try:
        cursor.execute(
            "CREATE TABLE Users(id integer, first_name text, last_name text,datecr text, passw text)"
        )
        cursor.execute(
            """INSERT INTO Users VALUES('{}','{}','{}','{}','{}')""".format(
                id, name, last_name, datecr, passwd_sha256))
    except sqlite3.OperationalError:
        cursor.execute(
            """INSERT INTO Users VALUES('{}','{}','{}','{}','{}')""".format(
                id, name, last_name, datecr, passwd_sha256))

    conn.commit()
    conn.close()
Example #2
0
def ins_db6(path=r"/home/red/PycharmProjects/python_belhard/db6"):

    f_name = ''
    s_name = ""
    age = 0
    phone_str = ''

    while True:
        f_name = input("Введите имя: ")
        if len(re.findall('[A-z\']+', f_name)) != 0:
            f_name = f_name
            break
        else:
            print('недопустимые символы для имени')
            f_name = ''

    while True:
        s_name = input("Введите имя: ")
        if len(re.findall('[A-z\']+', s_name)) != 0:
            s_name = s_name
            break
        else:
            print('недопустимые символы для фамилии')
            s_name = ''

    age = input("Введите возраст: ")

    datecr_tuple = datetime.timetuple(datetime.today())
    datecr = strftime('%Y', datecr_tuple)
    year_birth = int(datecr) - age

    while True:

        phone_numb = input("Введите номер телефона: ")

        phone_numb = phone_numb.replace('-', '')
        phone_numb = phone_numb.replace('(', '')
        phone_numb = phone_numb.replace(')', '')

        if re.match(r'[+375]|[8029]|[029]|[]|[29][0-9]{7}',
                    phone_numb) and len(phone_numb) > 6:
            phone_numb = phone_numb
            break
        else:
            print('некорректный номер телефона')

    if len(phone_numb) > 0:
        phone_str = '+37529' + phone_numb[-7:]
    else:
        phone_str = ''

    conn = sqlite3.connect(path)
    cursor = conn.cursor()

    id = 0
    try:
        id = (cursor.execute("SELECT max(id) FROM Phone_book").fetchall()[0]
              )[0] + 1
    except:
        id = 1

    cursor.execute(
        """INSERT INTO Phone_book VALUES({},"{}","{}",'{}',{})""".format(
            id, f_name, s_name, phone_str, year_birth))
    conn.commit()
    conn.close()
Example #3
0
def to_unix(datetime):
    return int(time.mktime(datetime.timetuple()) * 1000)