E
E
Edward_Elric2021-05-07 18:30:42
Python
Edward_Elric, 2021-05-07 18:30:42

How to unload messages from a dialogue in VK more efficiently?

Unloading all messages is not a problem, the problem is speed. It takes about 12 minutes to upload 295k messages, which is quite a long time. How to do it more efficiently?

resid = count #number of messages with the user
offset = 0
h = []
while resid > 0:
    message_users = vk_session.method('messages.getHistory', {'peer_id': user, 'count':200, "rev": 1, 'offset':offset})
    h += message_users['items']
    resid -= 200
    offset += 200
    print(resid)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yupiter7575, 2021-05-07
@yupiter7575

threading

S
ScriptKiddo, 2021-05-08
@ScriptKiddo

You need to use the execute
method Upload example

var result = [];

var offset = 0;
var peer_id = 123456;
var count = 100;
var cycles = 20;

while (cycles  != 0) {
  result.push(API.messages.getHistory({"peer_id": peer_id , "count":count, "rev": 1, "offset":offset}));
  offset = offset + count;
  cycles = cycles - 1;
};


return result ;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question