-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_dialogs.py
More file actions
53 lines (42 loc) · 1.39 KB
/
update_dialogs.py
File metadata and controls
53 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import vk_api
import datetime
import os
import time
import json
def get_vk_api():
file_descriptor = open("json.auth", "r")
auth = json.load(file_descriptor)
vk_session = vk_api.VkApi(auth["login"], auth["password"]);
vk_session.auth(token_only=True)
vk = vk_session.get_api()
return vk
def save_conversation(vk,conversation):
if ( True ): #conversation["peer"]["type"] == "user"):
offset = 0;
messages = []
while True:
response = vk.messages.getHistory(peer_id=conversation["peer"]["id"], count=200, offset=offset)
messages = messages + response["items"];
if len(response["items"]) != 200:
break
else:
offset += 200
file_descriptor = open(str(conversation["peer"]["id"]), 'w+')
print(messages,file = file_descriptor)#.write(json.dumps(messages))
file_descriptor.close()
def dowload_all_conversations(vk,target):
offset=0;
while True:
response = vk.messages.getConversations(offset=offset, count=200)
for conversation in response["items"]:
save_conversation(vk,conversation["conversation"])
if len(response["items"])!=200 :
break;
offset += 200
vk = get_vk_api()
try:
os.mkdir("dialogs")
except FileExistsError:
print ("already exist")
os.chdir("dialogs")
dowload_all_conversations(vk, 0)