-
Notifications
You must be signed in to change notification settings - Fork 0
/
serializer.py
42 lines (37 loc) · 1.47 KB
/
serializer.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
import json
import asyncio
class Serializer():
async def get(self, server:int, coun:int):
try:
if server == 0:
with open("rpg.json", "r", encoding="utf-8") as f:
return json.load(f)[0:coun]
elif server == 1:
with open("rp.json", "r", encoding="utf-8") as f:
return json.load(f)[0:coun]
elif server == 2:
with open("rp2.json", "r", encoding="utf-8") as f:
return json.load(f)[0:coun]
except:
return ['Строки ещё не загрузились']
async def longpollGet(self, server: int, ban: str):
if server == 0:
return await self.getLongpollLine('rpg.json', ban)
elif server == 1:
return await self.getLongpollLine('rp.json', ban)
elif server == 2:
return await self.getLongpollLine('rp2.json', ban)
async def getLongpollLine(self, server: str, ban: str):
try:
with open(server, "r", encoding="utf-8") as f:
try:
return await self.checkLongPoll(json.load(f)[0], ban)
except Exception:
return False
except:
return ['Строки ещё не загрузились']
async def checkLongPoll(self, line: str, ban: str):
if line[1:] != ban:
return [line[1:]]
else:
return False