forked from trofik00777/TenderHack-ITMEM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystem.py
More file actions
116 lines (108 loc) · 4.9 KB
/
Copy pathSystem.py
File metadata and controls
116 lines (108 loc) · 4.9 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
from aiohttp import ClientSession
from Sender import Sender
class System:
@staticmethod
async def __checkNet(): # проверяем работает ли интернет
async with ClientSession() as session:
try:
async with session.get("https://edu.pp24.dev/ru") as resp:
return 1
except:
return 0
async def create(self):
async with ClientSession() as session:
self.cookies = session.cookie_jar
if self.log:
print("Start login in account")
url = "https://old.edu.pp24.dev/api/Cssp/Authentication/BeginAuthentication?type=Password"
while True:
if await self.__checkNet():
async with ClientSession(cookie_jar=self.cookies) as session:
async with session.get(url) as resp:
if self.log:
print(await resp.text())
self.cookies = session.cookie_jar
token = await resp.text()
token = token[1:-1]
self.error = await self.__login(self.password, self.login, token)
if self.error == 0:
print("Succesfully login")
else:
print("Unseccusfully login")
break
if self.log:
print("Problem with internet")
def __init__(self, login: str, password: str, receive_mail, telegram_message, log: bool = False):
self.active = 1
self.log = log
self.password = password
self.login = login
self.telegram_message = telegram_message
self.sender = Sender(receive_mail, telegram_message)
# 0 - successful, -1 - error
async def __login(self, password: str, login: str, token: str):
url = "https://old.edu.pp24.dev/api/Cssp/Authentication/PerformAuthentication"
data = {"token": token, "operation": "LogIn",
"argument": {"values": {"login": f"{login}", "password": f"{password}"}}}
while True:
if await self.__checkNet():
async with ClientSession(cookie_jar=self.cookies) as session:
async with session.post(url, json=data) as response:
resp = await response.json()
self.cookies = session.cookie_jar
break
if self.log:
print("Problem with internet")
if resp['isSessionComplete'] == True:
url = "https://old.edu.pp24.dev/api/Cssp/Authentication/CheckAuthentication"
while True:
if await self.__checkNet():
async with ClientSession(cookie_jar=self.cookies) as session:
async with session.get(url) as response:
if self.log:
print(await response.text())
resp = await response.json()
if resp['isAuthenticated'] == False:
if self.log:
print("Failed login")
return -1
if self.log:
print("We succesfully login")
self.cookies = session.cookie_jar
return 0
if self.log:
print("Problem with internet")
else:
if self.log:
print("Something went wrong")
return -1
async def getItem(self, id: str):
URL = f"https://edu.pp24.dev/newapi/api/Auction/Get?auctionId={id}"
while True:
if await self.__checkNet():
async with ClientSession(cookie_jar=self.cookies) as session:
async with session.get(URL) as response:
if self.log:
print(await response.text())
resp = await response.json()
self.cookies = session.cookie_jar
return resp
if self.log:
print("Problem with internet")
async def getBet(self, id: str, rowversion: str, value: str):
url = "https://edu.pp24.dev/newapi/api/Auction/CreateBet"
data = {
'auctionId': id,
'rowVersion': rowversion,
'value': value
}
while True:
if self.__checkNet():
async with ClientSession(cookie_jar=self.cookies) as session:
async with session.post(url, json=data) as response:
if self.log:
print(await response.text())
self.cookies = session.cookie_jar
break
if self.log:
print("Problem with internet")