Пример #1
0
def test():
    # screencrop_name()
    # screencrop_name_adb()
    create_db.connect_db(create_db.DB_TEST_PATH)

    # exercise_workout_large_38_0
    exercise_name = 'Dumbbell Biceps Curl, On Knee, Underhand Grip'
    id_exercise_name = create_db.get_id_from_name(exercise_name)
    # print(id_exercise_name)
    index_exercise_name = create_db.get_image_count_from_name(exercise_name)
Пример #2
0
def add_dhcp_info(filelist):
    regexp = re.compile('(\S+) +(\S+) +\d+ +\S+ +(\d+) +(\S+)')
    result = []
    conn = connect_db("dhcp_snooping.db")
    for files in filelist:
        device = re.search('(\S+?)_\S+', os.path.basename(files)).group(1)
        with open(files) as f:
            for line in f:
                match = regexp.search(line)
                if match:
                    resstring = list(match.group(1, 2, 3, 4))
                    resstring.append(device)
                    result.append(tuple(resstring))
        query = f"update dhcp set active = ? where switch like '{device}'"
        write_to_db(conn, query, '0')
    insert = 'insert into dhcp values (?, ?, ?, ?, ?, 1, datetime("now"))'
    update = "update dhcp set ip = ?, vlan = ?, interface = ?, switch = ?, active = 1, last_active = datetime('now') where mac = ?"
    for line in result:
        if not write_to_db(conn, insert, line):
            print(f"string added to the dhcp table: {line}")
        else:
            tmp = list(line)[1::]
            tmp.append(line[0])
            line = tuple(tmp)
            print(
                f"updating values for mac {line[-1]}. New values: {line[0:-1:]}"
            )
            write_to_db(conn, update, line)
    conn.commit()
Пример #3
0
def remove_old_records():
    now = datetime.today().replace(microsecond=0)
    week_ago = now - timedelta(days=7)
    conn = connect_db("dhcp_snooping.db")
    print(f"removing old records (before {week_ago})")
    query = f"delete from dhcp where datetime(last_active) <= datetime('{week_ago}') and active == 0"
    writescriptto_db(conn, query)
    conn.commit()
Пример #4
0
def get_name_exercise():
    create_db.connect_db(create_db.DB_TEST_PATH)

    # SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))

    # exercise_name = ocr_core(os.path.join(SCRIPT_DIRECTORY, './name.jpg'))
    exercise_name = 'Ring Muscleup'

    id_exercise_name = create_db.get_id_from_name(exercise_name)
    print(id_exercise_name)
    index_exercise_name = create_db.get_image_count_from_name(exercise_name)
    print(index_exercise_name)
    for x in range(index_exercise_name):
        to_clipboard('exercise_workout_' + str(id_exercise_name) + '_' +
                     str(x))
        time.sleep(1)
        # screencrop()
        screencrop_adb()
        time.sleep(1)
        pyautogui.doubleClick(1637, 528)
Пример #5
0
def add_switches_info(source):
    with open(source) as f:
        switch_dict = yaml.safe_load(f)
        query = "INSERT into switches values (?, ?)"
        result = []
        for key in switch_dict:
            for items in switch_dict[key].items():
                result.append(items)
    conn = connect_db("dhcp_snooping.db")
    for line in result:
        if not write_to_db(conn, query, line):
            print(f'line added to switches table "{line[0]}     {line[1]}"')
        else:
            print(f"{line[0]} info already present in the table")
    conn.commit()
def test_connect_db():
    con = create_db.connect_db()
    assert con is not None
Пример #7
0
u = args.username
p = args.password
l = args.list
d = args.delete
e = args.edit
np = args.new_pass

# When only username and password args
if (u is not None and p is not None and l is False and d is False
        and e is False and np is None):

    if len(p) < 8:
        raise ValueError("Password is to short")

    cursor = connect_db()

    sql = f"SELECT * FROM users WHERE username='******'"
    cursor.execute(sql)

    if (cursor.rowcount > 0):
        raise ValueError('A duplicated recrod already exists')

    user = User(u, p)
    user.safe_to_db(cursor)
    close_connect_db()
    print("User has been created")

elif (u is not None and p is not None and l is False and d is False
      and e is True and np is not None):
Пример #8
0
def before_request():
    g.db = connect_db()