forked from MaxiFilippov/news_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_advirt.py
77 lines (63 loc) · 1.78 KB
/
set_advirt.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
import asyncio
from db import *
class Adv:
count_of_shows = 0
max_shows = 0
text = ''
session = 'inactive'
users = []
language = ''
def __init__(self):
pass
# For incremeting count_of_shows
@classmethod
def inc_count(self):
print("Incrementing")
self.count_of_shows += 1
@classmethod
def compare_language(self, lang):
if self.language == lang:
return True
return False
@classmethod
async def reset_count(self):
print('Reseting')
loop = asyncio.get_event_loop()
await loop.run_in_executor(None, reset_session, self.count_of_shows)
self.count_of_shows = 0
self.session = 'inactive'
self.users.clear()
@classmethod
def insert_user(self, username):
self.users.append(username)
@classmethod
def return_count(self):
return self.count_of_shows
@classmethod
def return_max_shows(self):
print(self.max_shows)
return self.max_shows
@classmethod
def check_user(self, username):
print("Checking user")
if username in self.users:
return False
return True
@classmethod
def return_text(self):
return self.text
@classmethod
def return_session(self):
return self.session
@classmethod
async def check_new_session(self, loop):
while True:
adv = get_adv()
if adv['session'] == 'active':
print("Session is active")
self.max_shows = int(adv['max_shows'])
self.text = adv['text']
self.session = 'active'
self.language = adv['language']
await asyncio.sleep(7200, loop=loop)
#Adv.check_new_session()