-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathGetNumbers.py
More file actions
134 lines (112 loc) · 3.89 KB
/
GetNumbers.py
File metadata and controls
134 lines (112 loc) · 3.89 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from typing import List
from onlinesimru.Extentions import TimeoutException
from onlinesimru.api import Api
import time
class GetNumbers(Api):
def price(self, service: str):
return self._get(f"/getPrice", {"service": service})["price"]
def get(
self,
service: str,
country: int = 7,
reject: List[int] = None,
extension: bool = False,
):
return self._get(
f"/getNum",
{
"service": service,
"country": country,
"reject": reject,
"extension": extension,
},
)["tzid"]
def state(
self,
message_to_code: int = 1,
orderby: str = "ASC",
msg_list: bool = True,
clean: bool = True,
repeat: bool = False,
):
type = "index"
if repeat:
type = "repeat"
return self._get(
f"/getState",
{
"message_to_code": message_to_code,
"orderby": orderby,
"msg_list": msg_list,
"clean": clean,
"type": type,
},
)
def stateOne(
self,
tzid: int,
message_to_code: int = 1,
msg_list: bool = True,
clean: bool = True,
repeat: bool = False,
):
type = "index"
if repeat:
type = "repeat"
return self._get(
f"/getState",
{
"tzid": tzid,
"message_to_code": message_to_code,
"msg_list": msg_list,
"clean": clean,
"type": type,
},
)[0]
def next(self, tzid: int):
return self._get(f"/setOperationRevise", {"tzid": tzid})
def close(self, tzid: int):
return self._get(f"/setOperationOk", {"tzid": tzid})
def ban(self, tzid: int):
return self._get(f"/setOperationOk", {"tzid": tzid, "ban": 1})
def tariffs(self):
return self._get(f"/getNumbersStats", {"country": "all"})
def tariffsOne(self, country: int = 7):
return self._get(f"/getNumbersStats", {"country": country})
def service(self):
return self._get(f"getService", {})["service"]
def serviceNumber(self, service: str):
return self._get(f"/getServiceNumber", {"service": service})["number"]
def getNumberFrom_tzid(self, tzid: int):
response = self.stateOne(tzid, 1, False)
print(f"[!] The phone-number is: [[{response['number']}]], country code is [[{response['country']}]].")
numberJson_ = {
'phoneNumber': response['number'],
'Country_Code': response['country'],
}
return numberJson_
def wait_code(self, tzid: int, timeout=10, callback=None, not_end=False, full_message=False):
__last_code: str = ""
_response_type: int = 1
if full_message:
_response_type = 0
counter = 0
response = self.stateOne(tzid, 1, False)
print(f"[!] Attention! Reminder the phone-number is: [[{response['number']}]], country code is [[{response['country']}]].")
while True:
time.sleep(timeout)
counter += 1
if counter >= 10:
raise TimeoutException("Timeout error")
response = self.stateOne(tzid, _response_type, False)
if "msg" in response and not not_end and response["msg"] != __last_code and response["msg"] != False:
__last_code = response["msg"]
self.close(tzid)
break
elif "msg" in response and not_end and response["msg"] != __last_code and response["msg"] != False:
__last_code = response["msg"]
self.next(tzid)
break
if callback:
callback(__last_code)
return __last_code