H
H
hahefle2020-02-21 14:26:47
Python
hahefle, 2020-02-21 14:26:47

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

1 answer(s)
P
Puma Thailand, 2020-02-21
@hahefle

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 question

Ask a Question

731 491 924 answers to any question