Answer the question
In order to leave comments, you need to log in
Aiohttp, rebuilding code for uploading photos?
hello, I noticed that the script takes a long time to perform actions, and aiohttp was advised to me, but at the same time, after looking at a lot of guides and forums, I did not understand how to rebuild this code for aiohttp (/aiovk)
(vk-api-proxy .. responds faster vpn +VK api, so there can be no problem with execution speed in this)
import requests
import json
import re
token = 'token'
version = '5.95'
alb = '270716038'
img = './photosvk/'
adres = '' #оставлять пустым
img_url = '' #оставлять пустым
chek = int(0)
for i in range(1000):
f = open('filelist.txt') # filelists.txt <- файл с названием.расширением фото(построчно)
line = f.readline().rstrip('\r\n')
while line:
adres = img + line
print(chek)
chek += int(1)
def get_url():
r = requests.get('https://vk-api-proxy.xtrafrancyz.net/method/photos.getUploadServer',
params={
'access_token': token,
'album_id': alb,
'v': version
}).json()
return r['response']['upload_url']
url = get_url()
file = {'file1': open(adres, 'rb')}
ur = requests.post(url, files=file).json()
result = requests.get('https://vk-api-proxy.xtrafrancyz.net/method/photos.save',
params={
'access_token': token,
'album_id': ur['aid'],
'server': ur['server'],
'photos_list': ur['photos_list'],
'hash': ur['hash'],
'v': version,
}).json()
open(adres).close
line = f.readline().rstrip('\r\n')
f.close()
print ('finish')
Answer the question
In order to leave comments, you need to log in
Isn't it easier to just run in many threads? That is, ten copies of the script, one and a half alterations, but immediately acceleration in the number of threads
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question