$ pip install slacker $ pip install vk_api
from slacker import Slacker import vk_api
slack = Slacker(' API token')
login, password = 'Login', 'pass' vk_session = vk_api.VkApi(login, password) try: vk_session.authorization() except vk_api.AuthorizationError as error_msg: print(error_msg) return vk = vk_session.get_api()
man_id = str(-29534144) #id , postidlist = vk.wall.get(owner_id=man_id, count=1, offset=0) # a = str(postidlist['items'][0]['id']) # id response = vk.wall.getComments(owner_id=man_id, post_id=a, count=1, sort='desc', offset=0) #
b = response['items'][0]['text'] #
slack.chat.post_message('#vk', ' : ' + b) # Slack
from slacker import Slacker import vk_api import time slack = Slacker(' token Slack bot') def main(): login, password = 'login', 'pass' vk_session = vk_api.VkApi(login, password) try: vk_session.authorization() except vk_api.AuthorizationError as error_msg: print(error_msg) return vk = vk_session.get_api() while True: # man_id = str(-29534144) #id postidlist = vk.wall.get(owner_id=man_id, count=1, offset=0) # a = str(postidlist['items'][0]['id']) # id time.sleep(5) ts = 10 bts = 10 while ts == bts: # , , . response = vk.wall.getComments(owner_id=man_id, post_id=a, count=1, sort='desc', offset=0) # ts = str(response['items'][0]['date']) # time.sleep(5) # 5 response = vk.wall.getComments(owner_id=man_id, post_id=a, count=1, sort='desc', offset=0) bts = str(response['items'][0]['date']) print(' ' + ts + bts) time.sleep(5) # response = vk.wall.getComments(owner_id=man_id, post_id=a, count=1, sort='desc', offset=0) # b = response['items'][0]['text'] # slack.chat.post_message('#vk', ' : ' + b) # Slack if __name__ == '__main__': main()
Source: https://habr.com/ru/post/281597/
All Articles