viewing paste Unknown #35580 | Python

Posted on the
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
def uploadPhoto(self, photoLinks, albumId, groupId = None):
        if len(photoLinks) > 5:
            print("cant send more than 5 imgs")
            return
            
        query = {
            'album_id': albumId,
            'access_token': self.token
        }
        
        if groupId is not None:
            query['group_id'] = groupId
        
        res = requests.get('https://api.vk.com/method/photos.getUploadServer', params=query)
        
        res = json.loads(res.text)['response']
        uploadUrl = res['upload_url']
        
        files = {}
        
        for i in range(0, 5):
            res = requests.get(photoLinks[i])
            filename = 'tempfiles/output{}.jpg'.format(i)
            with open(filename, 'w') as f:
                f.write(res.content)
            
            file = open(filename, 'rb')
            files['file{}'.format(i)] = file
        
        res = requests.post(uploadUrl, files=files)
        
        for file in files:
            file.close()
        
        res = json.loads(res.text)
        return res
        
Viewed 1003 times, submitted by Guest.