<jupyter_start><jupyter_text>TODO* now using app ImplicitSession, because aiovk can't auth from user side. Probably need to auth throw vk-api and then use aiovk.TokenSession  Experiment to asynchonously get users friends using aiovk lib<jupyter_code>from typing import List, Optional

import aiovk
import asyncio
import aiohttp
import vk_api
import requests
import json
login = input()
password = input()
proxy_address = input()
proxy_port = input()
s = requests.Session()
user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0'
s.headers.update({'User-agent': user_agent})
for proxy_protocol in ["http", "https"]:
    s.proxies.update({proxy_protocol: f"{proxy_address}:{proxy_port}"})
    
vk_api_session = vk_api.VkApi(login, password, session=s)
vk_api_session.auth()
access_token = vk_api_session.token["access_token"]
proxy = aiovk.drivers.ProxyDriver(proxy_address, proxy_port)
session = aiovk.TokenSession(access_token, driver=proxy)
async_vk_api = aiovk.API(session)
await async_vk_api.users.get(user_ids=1)
async def get_friends(user_id, async_api):
    return await async_api.friends.get(user_id=user_id)
await get_friends(491221043, async_vk_api)
with open("../resources/checkpoints/data_checkpoint.json") as f:
    user_data = json.load(f)
groups_to_get = user_data["68076353"]["groups"]
del user_data

async def get_group_wall(group_id, async_api):
    return await async_api.wall.get(owner_id=-1 * group_id, extended=False) # negative value means group, positive - user<jupyter_output>/usr/lib/python3.8/json/decoder.py:353: RuntimeWarning: coroutine 'Request.__call__' was never awaited
  obj, end = self.scan_once(s, idx)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback<jupyter_text>Asynchronous way<jupyter_code>class TokenSessionWithProxy:
    """wrapper for AsyncVkExecuteRequestPool from aiovk because it doesn't support passing
    Driver to session"""
    def __init__(self, proxy_address, proxy_port):
        self.proxy_address, self.proxy_port = proxy_address, proxy_port
    
    def __call__(self, token):
        proxy_driver = aiovk.drivers.ProxyDriver(self.proxy_address, self.proxy_port)
        return aiovk.TokenSession(token, driver=proxy_driver)

from aiovk.pools import AsyncVkExecuteRequestPool

async def get_groups_walls(groups_ids: List[int], access_token, pool_size=25, req_params: Optional[dict]=None):
    # !!!: TODO: should not await for one pool execute, need to make all executes() simultaneously and wait for results
    if req_params is None:
        req_params = {}
        
    groups_ids = groups_ids.copy()
    responses = []
    pool_executes = []
    
    while groups_ids:
        pool = AsyncVkExecuteRequestPool(token_session_class=TokenSessionWithProxy(proxy_address, proxy_port))
        
        for _ in range(pool_size):
            if not groups_ids:
                break
            group_id = groups_ids.pop(0)
            resp = pool.add_call("wall.get", access_token, {"owner_id": -1 * group_id, **req_params})
            responses.append(resp)
            
        pool_executes.append(pool.execute())
        
    await asyncio.gather(*pool_executes)
    return responses
from time import time

start_time = time()
groups_walls = await get_groups_walls(groups_to_get, access_token=session.access_token, req_params={"extended": False})
print("time needed", time() - start_time)
groups_walls[0].result<jupyter_output><empty_output><jupyter_text>synchronous way<jupyter_code>pool = vk_api.requests_pool.VkRequestsPool(vk_api_session)
%%time

responses = []
for idx, group in enumerate(groups_to_get):
    resp_raw = pool.method("wall.get", values={"owner_id": -1 * group, "extended": False})
    responses.append(resp_raw)
    if idx % 25 == 24:
        pool.execute()<jupyter_output>CPU times: user 595 ms, sys: 78.9 ms, total: 674 ms
Wall time: 25.5 s
{'fraction_non_alphanumeric': 0.10325245224574084, 'fraction_numerical': 0.016520392359318535, 'mean_word_length': 4.673499267935578, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '506511', 'license': 'MIT', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1266, 'n_words': 296, 'path': 'notebooks/aiovk.ipynb', 'repo_name': 'ProtsenkoAI/skady-user-vectorizer', 'size': '3874'}