add checking but not complete

This commit is contained in:
Leon Vita 2022-12-29 06:13:03 +00:00
parent 065d0f23bb
commit e59fec22a7
2 changed files with 21 additions and 14 deletions

35
data.py
View File

@ -2,6 +2,7 @@ import sqlite3
create = sqlite3.connect("db") create = sqlite3.connect("db")
connect = create.cursor() connect = create.cursor()
# Create TABLE only used once
# connect.execute("""CREATE TABLE IPS ( # connect.execute("""CREATE TABLE IPS (
# user_vpn, # user_vpn,
# user_ips text # user_ips text
@ -9,25 +10,31 @@ connect = create.cursor()
def insert_ips(): def insert_ips():
#user input #user input
user_name = input(str("username: ")) # user_name = input(str("username: "))
user_ips = input(str("ip: ")) # user_ips = input(str("ip: "))
#add input to list inside tuple # #add input to list inside tuple
users = [ # users = [
(user_name,user_ips) # (user_name,user_ips)
] # ]
# insert 2 values to IPS TABLE # insert 2 values to IPS TABLE
connect.executemany("INSERT INTO IPS VALUES (?,?) ", users) # connect.executemany("INSERT INTO IPS VALUES (?,?) ", users)
# commit the input to db # commit the input to db
create.commit() # create.commit()
# read db # read db with row id
connect.execute("SELECT * FROM IPS") connect.execute("SELECT rowid, * FROM IPS") #to check with rowid use WHERE rowid = 1
#close the db #close the db
def checking(): def checking():
items = connect.fetchall() userinput = '10.10.11.1'
items = connect.fetchall()
for item in items: for item in items:
print(item[1]) item_list = [item[2]]
print(item_list)
# if item_list == userinput:
# print('ip exist')
# break
# else:
# print('new ip')
# break
#call the func #call the func
insert_ips() insert_ips()
checking() checking()

BIN
db

Binary file not shown.