# pip3 install vk_api
import vk_api, sys, time
from vk_api import exceptions
from datetime import datetime
from random import randint
class VkStatus:
def __init__(self):
self.vk_session = None
self.token = "$ Токен сюда $"
def auth(self):
try:
self.vk_session = vk_api.VkApi(
token=self.token,
)
except exceptions.AccessDenied:
return "[DynamicStatus] Login failed; [reason: AccessDenied;]"
except exceptions.AccountBlocked:
return "[DynamicStatus] Login failed; [reason: AccountBlocked;]"
except exceptions.AuthError:
return "[DynamicStatus] Login failed; [reason: AuthError;]"
except exceptions.TwoFactorError:
return "[DynamicStatus] Login failed; [reason: TwoFactorError;]"
finally:
return "[DynamicStatus] Login successfull;"
def set_status(self, status: str):
try:
self.vk_session.method(
"status.set", {
"text": status,
}
)
return True
except:
return False
def run(self):
a = self.auth()
print(a)
if a != "[DynamicStatus] Login successfull;":
sys.exit(1)
print("[DynamicStatus] Starting status changer;")
while True:
status = VkStatus.get_status()
g = self.set_status(
status
)
if g:
print("[DynamicStatus] Status changed;")
else:
print("[DynamicStatus] Failed to change status;")
# Можно статично сделать статично но почему бы и так не сделать ?
r = randint(30, 60)
print(f"[DynamicStatus] Next status change after {r} seconds;")
time.sleep(r)
def get_status() -> str:
now = datetime.now()
NY = datetime(2022, 1, 1)
d = NY - now
# Что бы было красиво, сделал так. Может какой то индус сделает это по другому но главное, что работает
better_lang = {
"часов": [0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
"часа": [22, 23, 24, 3, 2, 4],
"час": [1,21,]
}
better_lang2 = {
"день": [1, 21,],
"дней": [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26, 27, 28, 29, 30,],
"дня": [22, 23, 24, 2, 3, 4]
}
mm,ss = divmod(d.seconds, 60)
hh,mm = divmod(mm, 60)
# Это тоже костыль но работает ведь :\
hrs_text = ""
day_text = ""
for i, k in better_lang.items():
if hh in k:
hrs_text = i
for i, k in better_lang2.items():
if d.days in k:
day_text = i
return f'? До нового года: {d.days} {day_text} {hh} {hrs_text} {mm} мин'
if __name__ == "__main__":
VkStatus().run()