makeHTML_YT.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import csv
  2. import dataset
  3. def readTemplate():
  4. upper_lines = ''
  5. with open('youtubeTable_upper.html',encoding='UTF-8') as f:
  6. upper_lines = f.readlines()
  7. lower_lines = ''
  8. with open('youtubeTable_lower.html',encoding='UTF-8') as f:
  9. lower_lines = f.readlines()
  10. return upper_lines, lower_lines
  11. upper_lines, lower_lines = readTemplate()
  12. dataLines = []
  13. with open('youtubeReport.csv', newline='',encoding='UTF-8') as csvfile:
  14. rows = csv.reader(csvfile)
  15. for row in rows:
  16. dataLines.append('<tr style="display: none;">')
  17. for item in row:
  18. dataLines.append('<td>'+item[:15]+'</td>')
  19. #db['ytVideos'].insert({'channelTitle':row[0],'subscribes':row[1],'description':row[2]
  20. #,'videoTitle':row[3],'publishedAt':row[4],'viewCount':row[5],'likeCount':row[6],'favoriteCount':row[7]})
  21. dataLines.append('</tr>')
  22. path = 'youtueTemplate.html'
  23. f = open(path, 'w',encoding='UTF-8')
  24. for l in upper_lines:
  25. f.write(l+'\n')
  26. for l in dataLines:
  27. f.write(l+'\n')
  28. for l in lower_lines:
  29. f.write(l+'\n')
  30. f.close()
  31. '''
  32. <tr style="display: none;">
  33. <td>10</td>
  34. <td>Table cell</td>
  35. <td>Table cell</td>
  36. <td>Table cell</td>
  37. <td>Table cell</td>
  38. <td>Table cell</td>
  39. <td>Table cell</td>
  40. </tr>
  41. '''