-
Notifications
You must be signed in to change notification settings - Fork 4
/
service.py
79 lines (63 loc) · 2.15 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import json
import random
import string
import requests
import conf.config as cfg
def randomName():
names = cfg.names
return random.choice(names)
def randomEmail():
emails = cfg.emails
return randomName() + randomNums() + random.choice(emails)
def randomPass():
return randomName() + randomNums()
def randomNums():
ls = [str(random.randint(10, 99)) for i in range(2)]
return "".join(ls)
def randomToken():
letters = string.ascii_letters + string.digits
return "".join(random.choice(letters) for i in range(30))
class Service:
def __init__(self, service, phone, timeout):
self.service = service
self.phone = phone
self.timeout = timeout
def __parse_data(self):
if "data" in self.service:
self.datatype = "data"
self.payload = self.service["data"]
elif "json" in self.service:
self.datatype = "json"
self.payload = self.service["json"]
else:
self.datatype = "url"
self.payload = json.dumps({"url": self.service["url"]})
def __replace_data(self):
for old, new in {
"'": '"',
"%phone%": self.phone,
"%name%": randomName(),
"%email%": randomEmail(),
"%password%": randomPass(),
"%token%": randomToken()
}.items():
if old in self.payload:
self.payload = self.payload.replace(old, new)
def get_domain_name(self):
""" Returns domain name of service. """
return self.service["url"].split('/')[2]
def send_request(self):
""" Send sms request to the server of service. """
self.__parse_data()
self.__replace_data()
session = requests.Session()
request = requests.Request("POST", self.service["url"])
self.payload = json.loads(self.payload)
if self.datatype == "json":
request.json = self.payload
elif self.datatype == "data":
request.data = self.payload
else:
request.url = self.payload["url"]
request = request.prepare()
session.send(request, timeout=self.timeout)