1234567891011121314151617181920212223242526272829303132 |
- import os
- import pandas as pd
- import pickle
- import psycopg2
- conn = psycopg2.connect(dbname="BiddingKG",user="postgres",password="postgres",host="192.168.2.101")
- cursor = conn.cursor()
- def load(path):
- '''
- 读取对象
- @Arugs:
- path: 读取的路径
- @Return:
- 读取的对象
- '''
- with open(path, 'rb') as f:
- object = pickle.load(f)
- return object
-
- for file in os.listdir(""):
- if file[-2:]=="pk":
- #if file[-9:-6] in ["l0.","l1.","l2.","l8."]:
- df = load("./"+file)
- for i in range(len(df)):
- if df.loc[i]['projectcode']!="" or df.loc[i]['projectname']!="":
- sql = " insert into project(doc_id,projectCode,projectName) values('"+df.loc[i]['doc_id']+"','"+df.loc[i]['projectcode']+"','"+df.loc[i]['projectname']+"')"
- #print(sql)
- print(file,i)
- cursor.execute(sql)
- conn.commit()
- conn.close()
|