回覆列表
  • 1 # 小雪020

    #!/usr/bin/python

    # -*- coding: UTF-8 -*-

    import os

    import sys

    import datetime

    import pymysql

    def read_insert(filename, slot_type_id):

    file = open(filename)

    i = 0

    j = 0

    list = []

    db = pymysql.connect(host="test", user="test", passwd="test", port=3306, db="test", charset="utf8")

    cursor = db.cursor()

    sql = "insert into test(slot_type_id, type, value, gmt_modify, gmt_create) values (%s, %s, %s, %s, %s)"

    for line in file:

    data = (slot_type_id, "const", (line.replace("\n","")),

    datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),

    datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

    list.append(data)

    if i > 5000:

    cursor.executemany(sql, list)

    db.commit()

    print("插入", j)

    i = 0

    list = []

    i = i + 1

    j = j + 1

    if i > 0:

    cursor.executemany(sql, list)

    db.commit()

    db.close()

    file.close()

    print("ok")

    if __name__ == "__main__":

    read_insert(sys.argv[1], sys.argv[2])

  • 中秋節和大豐收的關聯?
  • 上聯:海棠花花開紅似海,如何對下聯?