toDBfb.py 474 B

12345678910111213141516
  1. import csv
  2. import dataset
  3. # 開啟 CSV 檔案
  4. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/microfilm?charset=utf8mb4')
  5. with open('fbReport.csv', newline='',encoding='UTF-8') as csvfile:
  6. # 讀取 CSV 檔案內容
  7. rows = csv.reader(csvfile)
  8. # 以迴圈輸出每一列
  9. for row in rows:
  10. db['fbPosts'].insert({'club':row[0],'clubLikes':row[1],'postLikes':row[2]
  11. ,'content':row[3],'date':row[4],'shares':row[5]})
  12. db.close()