toDByt.py 559 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('youtubeReport.csv', newline='',encoding='UTF-8') as csvfile:
  6. # 讀取 CSV 檔案內容
  7. rows = csv.reader(csvfile)
  8. # 以迴圈輸出每一列
  9. for row in rows:
  10. print(row[5])
  11. db['ytVideos'].insert({'channelTitle':row[0],'subscribes':row[1],'description':row[2]
  12. ,'videoTitle':row[3],'publishedAt':row[4],'viewCount':row[5],'likeCount':row[6],'favoriteCount':row[7]})
  13. db.close()