imp_csv.py 429 B

1234567891011121314151617181920
  1. import codecs
  2. import dataset
  3. fr=codecs.open('c:/tmp/Queries.csv','r','utf-8')
  4. lines=fr.readlines()
  5. fr.close()
  6. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  7. table=db['hhh_gsc_imp']
  8. for l in lines:
  9. # print(l)
  10. elmts=l.strip().split(',')
  11. print(elmts[0])
  12. print(elmts[4])
  13. try:
  14. table.insert({'query':elmts[0],'position':elmts[4]})
  15. except:
  16. print('except')