This repository has been archived by the owner on Oct 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Alice.py
96 lines (79 loc) · 2.84 KB
/
Alice.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import datetime
import time
from pytils import numeral
from pytils.third import six
import vk
import GetSettingsModule
# Основные параметры
# Версия VK API
API_VERSION = 5.73
SCRIPT_TIME_SLEEP = 4
CHAT_ID_DICT = {
"1": "4",
"2": "13",
"3": "15",
"4": "17",
"5": "26",
"6": "52",
"7": "53",
"8": "54",
}
class AliceClass(object):
"""
Класс с основной логикой работы Алиски
"""
def __init__(self):
vk_token = GetSettingsModule.GetSettings()
session = vk.Session(access_token=vk_token)
self.api = vk.API(session)
self.api_version = API_VERSION
# Счетчик до 1 сентября
a = "2019-12-31".split("-")
self.counter = datetime.date(int(a[0]), int(a[1]), int(a[2]))
while True:
self.processing_method()
time.sleep(SCRIPT_TIME_SLEEP)
def processing_method(self):
# Счетчик дней до НГ
cc = self.counter - datetime.date.today()
dd = int(str(cc).split()[0])
left_days = self.word_formater(
numeral.choose_plural(int(dd), (u"день", u"дня", u"дней"))
)
# left_str = self.word_formater(numeral.choose_plural(int(dd), (u'Остался', u'Осталось', u'Осталось')))
# Названия чатиков
chat_titles = {
"1": "IV Курс | До НГ " + str(dd) + " " + left_days,
"2": "III Курс | До НГ " + str(dd) + " " + left_days,
"3": "3ПКС-117 | До НГ " + str(dd) + " " + left_days,
"4": "II Курс | До НГ " + str(dd) + " " + left_days,
"5": "4ПКС-116 | До НГ " + str(dd) + " " + left_days,
"6": "I Курс | До НГ " + str(dd) + " " + left_days,
"7": "FA | До НГ " + str(dd) + " " + left_days,
"8": "ПМиИТ | До НГ " + str(dd) + " " + left_days,
}
# Чекаем названия бесед
for i in range(len(CHAT_ID_DICT)):
time.sleep(0.5)
conf_id = CHAT_ID_DICT[str(i + 1)]
name_now = self.api.messages.getChat(chat_id=conf_id, v=self.api_version)[
"title"
]
# Если надо, то меняем название
if name_now != chat_titles[str(i + 1)]:
try:
self.api.messages.editChat(
chat_id=conf_id,
title=chat_titles[str(i + 1)],
v=self.api_version,
)
except:
continue
def word_formater(self, s):
if six.PY3:
out = s
else:
out = s.encode("UTF-8")
return out
if __name__ == "__main__":
AliceClass()