Answer the question
In order to leave comments, you need to log in
Why does python vk_api take a long time to process with a stand alone application?
The code unloads information about group subscribers in csv
import vk_api, csv
token = "1234"
vk_session = vk_api.VkApi(token=token,app_id="1234")
vk = vk_session.get_api()
print(vk)
##Сохраняет бд Юзеров в FILENAME
def bdGroupUsers(group_id=29534144):
FILENAME = "out12.csv"
count_members = vk.groups.getMembers(group_id=group_id, count=0)["count"] #число участников в группе
while_count= count_members//11000 + 1
def code(offset=0):
code = '''
var i = 0;
var members = [];
var offset = '''+str(offset)+''';
while(i < 11){
members.push(API.groups.getMembers({"group_id": '''+str(group_id)+ ''', "offset": offset, "fields": "can_write_private_message, city"})["items"]);
i = i + 1;
offset = offset + 1000;
}
return members;
'''
return code
offset = 0
ku = 0
df=[]
columns = ["can_access_closed", "can_write_private_message", 'city', 'deactivated', 'first_name', 'id', 'is_closed', 'last_name'] #заголовки таблицы
with open(FILENAME, "w", newline="", encoding='utf8') as file:
writer = csv.DictWriter(file, fieldnames=columns)
writer.writeheader()
with open(FILENAME, "w", newline="", encoding='utf8') as file:
writer = csv.DictWriter(file, fieldnames=columns)
while ku <while_count-1:
y = vk.execute(code=code(offset))
for i in y:
for j in i:
writer.writerow(j)
print(ku)
offset+=11000
ku+=1
bdGroupUsers()
Answer the question
In order to leave comments, you need to log in
id
users - it is performed quickly. city
and can_write_private_message
how long it thinks and crashes with an error. id
, and then request city
andcan_write_private_message
only for beginners.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question