Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #setting up the browser
  2. mySite = 'http://example.com/managament.php?'
  3. postData = {'UserID' : '', 'Action':'Delete'}
  4. job_tab1_user1 = [1,2,3]
  5. job_tab2_user1 = [4,5,6]
  6. job_tab1_user2 = [7,8,9]
  7. job_tab2_user2 = [10,12,13]
  8. .... till user1000
  9. #i want to point out that the lists are 100% different
  10. def user1_jobs:
  11. for i in job_tab1_user1:
  12. browser.open("http://example.com/jobs.php?actions="+i)
  13. browser.open(mySite, Post_data)
  14. for i in job_tab2_user1:
  15. browser.open("http://example.com/jobs.php?actions="+i)
  16. browser.open(mySite, Post_data)
  17. def user2_jobs:
  18. for i in job_tab1_user2:
  19. browser.open("http://example.com/jobs.php?actions="+i)
  20. browser.open(mySite, Post_data)
  21. for i in job_tab2_user2:
  22. browser.open("http://example.com/jobs.php?actions="+i)
  23. browser.open(mySite, Post_data)
  24. ... and so on till user 1000
  25.  
  26. t_user1 = threading.Thread(target=user1_jobs, args=[])
  27. t_user1.start()
  28. t_user2 = threading.Thread(target=user2_jobs, args=[])
  29. t_user2.start()
  30.  
  31. from threading import *
  32.  
  33. submits = [[1,2,3], [3,4,5], [6,7,8]]
  34.  
  35. class worker(Thread):
  36. def __init__(self, site, postdata, data):
  37. Thread.__init__(self)
  38. self.data = data
  39. self.site = site
  40. self.postdata = postdata
  41. self.start()
  42. def run(self):
  43. for i in self.data:
  44. browser.open("http://example.com/jobs.php?actions="+str(i))
  45. browser.open(self.site, self.postdata)
  46. for obj in submits:
  47. worker('http://example.com/managament.php?', {'UserID' : '', 'Action':'Delete'}, submits)
  48.  
  49. for index in range(0,1000):
  50. worker('http://example.com/managament.php?', {'UserID' : '', 'Action':'Delete'}, [i for i in range(1,4)])
  51.  
  52. # define your variables here
  53. NUM_USERS = 1000
  54. NUM_JOBS_PER_USER = 3
  55. NUM_TABS_PER_USER = 2
  56. URL_PART = "http://example.com/jobs.php?actions="
  57.  
  58. # populate our list of jobs
  59. # the structure is like this: jobs[user][tab][job]
  60.  
  61. jobs = [[[0 for y in range(NUM_JOBS_PER_USER)]
  62. for x in range(NUM_TABS_PER_USER)]
  63. for x in range(NUM_USERS)]
  64. p = 1
  65. for i in range(NUM_USERS):
  66. for j in range(NUM_TABS_PER_USER):
  67. for k in range(NUM_JOBS_PER_USER):
  68. jobs[i][j][k] = p
  69. p += 1
  70.  
  71.  
  72. # create a generator that builds our thread functions
  73. def generateFunctions(jobs):
  74. for user in jobs:
  75. for tab in user:
  76. for job in tab:
  77. def f():
  78. browser.open(URL_PART + str(job))
  79. browser.open(mySite, Post_data)
  80. yield f
  81.  
  82. # create and start threads, add them to a list
  83. # if we need to preserve handlers for later use
  84. threads = []
  85. for f in generateFunctions(jobs):
  86. thr = threading.Thread(target = f, args=[])
  87. thr.start()
  88. threads.append(thr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement