icons.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from _clickjob import *
  2. custlist = ["The Icons_EN", "The Icons_ZH"]
  3. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  4. def reset(cust):
  5. k=db.query('select * from seo.seo_nton_custkw where cust="' + cust + '"')
  6. u=db.query('select * from seo.seo_nton_custurl where cust="' + cust + '"')
  7. #TAG ABOVE AND UNTAG BELOW FOR DEBUG
  8. #ds=hhhdb.query('select * from seo.seo_articles where cust=')
  9. kwd=[]
  10. urld=[]
  11. for i in k:
  12. kwd.append(i['kw'].replace('\xa0',' '))
  13. for i in u:
  14. urld.append(i['url'].replace('\xa0',' '))
  15. random.shuffle(kwd)
  16. random.shuffle(urld)
  17. return [kwd,urld,c]
  18. runcount=0
  19. while True:
  20. try:
  21. data=[]
  22. cust = custlist
  23. print("Gathering data...")
  24. for c in cust:
  25. data.append(reset(c))
  26. print('Data collected')
  27. dataok = 1
  28. print(len(data))
  29. except:
  30. dataok = 0
  31. print("Error while collecting data.")
  32. if dataok == 1:
  33. for i in range(10):
  34. print("Run " + str(runcount+1))
  35. target = random.choice(data) # START HERE
  36. target_kw = random.choice(target[0])
  37. print(target_kw)
  38. statuscode = execute(target[1], target_kw, target[2]) # target[1] is URL list
  39. if statuscode == 444:
  40. print("Completed ", runcount, " times before being caught")
  41. time.sleep(300)
  42. else:
  43. runcount+=1
  44. else:
  45. time.sleep(60)