Files
VK_autolike_bot/main.py
2024-02-26 22:52:39 +03:00

32 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
import threading
TARGET_GROUP_ID = 'ID_целевого_сообщества'
ACCESS_TOKEN = 'ваш_токен'
def like_post(event, vk):
try:
vk.likes.add(type='post', owner_id=event.group_id, item_id=event.wall_id)
print("Пост от {} успешно лайкнут.".format(event.group_id))
except vk_api.exceptions.ApiError as e:
print("Ошибка VK API при лайке поста:", e)
except Exception as e:
print("Необработанная ошибка при лайке поста:", e)
def process_events(vk, longpoll):
print("Бот запущен. Лайкать посты из сообщества {}.".format(TARGET_GROUP_ID))
for event in longpoll.listen():
if event.type == VkEventType.WALL_POST_NEW and str(event.group_id) == TARGET_GROUP_ID:
thread = threading.Thread(target=like_post, args=(event, vk))
thread.start()
def main():
vk_session = vk_api.VkApi(token=ACCESS_TOKEN)
vk = vk_session.get_api()
longpoll = VkLongPoll(vk_session)
process_events(vk, longpoll)
if __name__ == '__main__':
main()