-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVKpage.py
More file actions
50 lines (45 loc) · 1.94 KB
/
VKpage.py
File metadata and controls
50 lines (45 loc) · 1.94 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
# Подключение модулей
import requests
import time
import sqlite3
# Token и id
token = '3e1c74eba6c0cf3715a42c2ba4b20c91237c4cf1e59833d9001a5ffedc7fa6b7a13c3a907de880aced1d3'
page_id = 'dm'
# Основной код
def vk_download(method, parameters, token=token):
url = 'https://api.vk.com/method/' + method + '?' + parameters + '&access_token=' + token + "&v=5.21"
response = requests.get(url)
try:
return (response.json())['response']
except:
print('Пожалуйста обновите токен, для этого воспользуйтесь ссылкой из файла main.py')
exit()
title_page = vk_download('users.get', 'user_ids=' + page_id)
new_id = str(title_page[0]['id'])
wall = vk_download('wall.get', 'owner_id=' + new_id)
count_notes = wall['count']
name_page = title_page[0]['first_name'] + ' ' + title_page[0]['last_name']
n = int(input('На странице '+str(count_notes)+' записей. Сколько скачаем записей? '))
conn = sqlite3.connect(name_page+'.db')
cur = conn.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS wall(
number TEXT,
author TEXT,
comments TEXT,
likes TEXT,
reposts TEXT);
""")
for i in range(0, n):
param = '&count=1&offset=' + str(i)
note = vk_download('wall.get', 'owner_id=' + new_id + param)
note = note['items'][0]
author_note, coments_count = 'Гость', str(note['comments']['count'])
likes_count, reposts_count = str(note['likes']['count']), str(note['reposts']['count'])
if int(note['from_id']) == int(note['owner_id']):
author_note = 'Владелец'
information_recording = (i, author_note, coments_count, likes_count, reposts_count)
cur.execute("INSERT INTO wall VALUES(?, ?, ?, ?, ?);", information_recording)
conn.commit()
time.sleep(0.5)
print('Записей скачано:', i + 1)
print('Посты скачаны. Всего скачано: ' + str(n))