D
D
Dmitry2019-06-25 15:34:38
Python
Dmitry, 2019-06-25 15:34:38

How to solve the problem, after receiving data from the server, the bot for VK sends them 12 times and only to one group, and not to several?

there are 3 arrays in which the VK group numbers and, accordingly, 3 keywords, finding which the bot sends the text and attachments to offer news to the community by entering 3 keywords in the conversation, it turns out that the bot sends this message 12 times only to groups by the first keyword, and the rest ignores, how to make others also receive this message and only once?
flask bot, functional part:

if auto in data['object']['text']:
            attachments = data['object']['attachments']
            if len(attachments) != 0:
                for i in attachments:
                    p_type = i['type']
                    p_owner_id = i[p_type]['owner_id']
                    p_media_id = i[p_type]['id']
        
                    attachments_list.append(p_type + str(p_owner_id) + '_' + str(p_media_id))
                a_list = ','.join(attachments_list)
                for n in auto_group:
                    vk_api_p.wall.post(owner_id=n, message=data['object']['text'], attachments=a_list)
                    time.sleep(10)
                    return 'ok'
                return 'ok'
            else:
                for n in auto_group:
                    vk_api_p.wall.post(owner_id=n, message=data['object']['text'])
                    time.sleep(10)
                return 'ok'
            return 'ok'        
        
        elif animal in data['object']['text']:
            attachments = data['object']['attachments']
            if len(attachments) != 0:
                for i in attachments:
                    p_type = i['type']
                    p_owner_id = i[p_type]['owner_id']
                    p_media_id = i[p_type]['id']
        
                    attachments_list.append(p_type + str(p_owner_id) + '_' + str(p_media_id))
                a_list = ','.join(attachments_list)
                for n in auto_group:
                    vk_api_p.wall.post(owner_id=n, message=data['object']['text'], attachments=a_list)
                    time.sleep(10)
                    return 'ok'
                return 'ok'
            else:
                for n in auto_group:
                    vk_api_p.wall.post(owner_id=n, message=data['object']['text'])
                    time.sleep(10)
                return 'ok'
            return 'ok'        
        
        elif learn in data['object']['text']:
            attachments = data['object']['attachments']
            if len(attachments) != 0:
                for i in attachments:
                    p_type = i['type']
                    p_owner_id = i[p_type]['owner_id']
                    p_media_id = i[p_type]['id']
        
                    attachments_list.append(p_type + str(p_owner_id) + '_' + str(p_media_id))
                a_list = ','.join(attachments_list)
                for n in auto_group:
                    vk_api_p.wall.post(owner_id=n, message=data['object']['text'], attachments=a_list)
                    time.sleep(10)
                    return 'ok'
                return 'ok'
            else:
                for n in auto_group:
                    vk_api_p.wall.post(owner_id=n, message=data['object']['text'])
                    time.sleep(10)
                return 'ok'
            return 'ok'        
        return 'ok'
    return 'ok'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-07-04
@ipatov_dn

The question was solved by removing all returns except the last key

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question