content_gap.py 799 B

12345678910111213141516171819202122232425262728293031323334
  1. import dataset
  2. import codecs
  3. import os
  4. fname=os.path.abspath(__file__)
  5. elmts=fname.split(os.path.sep)
  6. path2=os.path.sep.join(elmts[0:-1])
  7. keysdir=path2+os.path.sep
  8. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
  9. #tablename='gap_searchome'
  10. #tablename='gap_hhh'
  11. tablename='gap_d100'
  12. #db.query('delete from '+tablename)
  13. table=db[tablename]
  14. #fr=codecs.open('hhh/data/searchome.csv','r','utf-16')
  15. #fr=codecs.open('hhh/data/hhh.csv','r','utf-16')
  16. fr=codecs.open('C:\\Users\\jared\\Downloads\\d100.csv','r','utf-16')
  17. lines=fr.readlines()
  18. fr.close()
  19. for l in lines[3:]:
  20. elmts=l.split('\t')
  21. # print(elmts)
  22. print(elmts[0])
  23. print(elmts[2])
  24. cnt=0
  25. try:
  26. cnt=int(elmts[2])
  27. except:
  28. cnt=0
  29. table.insert({'q':elmts[0],'cnt':cnt})