add_SEO.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import dataset
  2. def insert_db(member):
  3. dic_tmp = {}
  4. dic_tmp['kw'] = member[0]
  5. dic_tmp['page'] = member[1]
  6. dic_tmp['domain'] = member[2]
  7. dic_tmp['category'] = "hhh-faq"
  8. result = db['seo_clickjobs'].insert(dic_tmp)
  9. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  10. #add_list = [('小坪數分割場域',0,'hhh.com.tw'),('小坪數 改造',0,'hhh.com.tw'),('小坪數格局',0,'hhh.com.tw'),('小坪數隔間',0,'hhh.com.tw'),('小坪數場域',0,'hhh.com.tw'),('小坪數場域設計',0,'hhh.com.tw'),('小坪數場域動線',0,'hhh.com.tw'),('小坪數場域規劃',0,'hhh.com.tw'),('小宅場域設計',0,'hhh.com.tw'),('小宅分割場域',0,'hhh.com.tw'),('小宅隔間',0,'hhh.com.tw')]
  11. while True :
  12. add_list = input("請輸入:")
  13. member=[]
  14. kw_string : str
  15. page_string : str
  16. ca_string : str
  17. check = 0
  18. for word in add_list:
  19. if word == '\'' and check == 0:
  20. kw_string = ""
  21. check = 1
  22. elif check == 1:
  23. if word == '\'':
  24. member.append(kw_string)
  25. kw_string = ""
  26. check = 2
  27. else :
  28. kw_string += word
  29. elif check == 2 :
  30. if word == ',':
  31. check =3
  32. page_string = ""
  33. elif check == 3 :
  34. if word ==',':
  35. member.append(int(page_string))
  36. page_string = ""
  37. check = 4
  38. else:
  39. page_string += word
  40. elif check == 4 :
  41. if word == '\'' :
  42. check = 5
  43. ca_string = ""
  44. elif check ==5:
  45. if word == '\'' :
  46. check = 0
  47. member.append(ca_string)
  48. ca_string = ""
  49. insert_db(member)
  50. member = []
  51. else :
  52. ca_string += word