getDatas.py 944 B

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import pandas as pd
  3. import pickle
  4. import psycopg2
  5. conn = psycopg2.connect(dbname="BiddingKG",user="postgres",password="postgres",host="192.168.2.101")
  6. cursor = conn.cursor()
  7. def load(path):
  8. '''
  9. 读取对象
  10. @Arugs:
  11. path: 读取的路径
  12. @Return:
  13. 读取的对象
  14. '''
  15. with open(path, 'rb') as f:
  16. object = pickle.load(f)
  17. return object
  18. for file in os.listdir("."):
  19. if file[-2:]=="pk":
  20. #if file[-9:-6] in ["l0.","l1.","l2.","l8."]:
  21. df = load("./"+file)
  22. for i in range(len(df)):
  23. if df.loc[i]['projectcode']!="" or df.loc[i]['projectname']!="":
  24. sql = " insert into project(doc_id,projectCode,projectName) values('"+df.loc[i]['doc_id']+"','"+df.loc[i]['projectcode']+"','"+df.loc[i]['projectname']+"')"
  25. #print(sql)
  26. print(file,i)
  27. cursor.execute(sql)
  28. conn.commit()
  29. conn.close()