icons.py 1.5 KB

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