<filename>ips/intosql.py
import sqlite3

def init():
    sql = """
    CREATE TABLE p_iplist(
    ID INT PRIMARY KEY     NOT NULL,
    TYPE CHAR(10) NOT NULL,
    IP CHAR(30) NOT NULL,
    PORT INT NOT NULL
    )
    """
    connect = sqlite3.connect("testsqlite.db")
    cursor = connect.cursor()
    cursor.execute(sql)
    cursor.close()
    connect.commit()
 
    # 第七步，关闭数据库
    connect.close()
def findid():
    connect = sqlite3.connect("testsqlite.db")
    cursor = connect.cursor()
    sql = "SELECT ID  FROM p_iplist"
    a = cursor.execute(sql)
    a = a.fetchall()
    cursor.close()
    return a[-1][-1]
def into(i):
    connect = sqlite3.connect("testsqlite.db")
    cursor = connect.cursor()
    id = findid()
    sql = """
    INSERT INTO p_iplist(ID,TYPE,IP,PORT)
    VALUES
    (%u,%s,%s,%u)
    """
    %(id,i['ix'], i['ip'].split(":")[0],
        i['ip'].split(":")[1])
    cursor.execute(sql)
    cursor.close()
    connect.commit()
    connect.close()
    
    