Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1.           if data["type"] == "message_new":
  2.                 object = data["object"]
  3.                 id = object["peer_id"]
  4.                 msgID = object["id"]
  5.                 body = object["text"]
  6.                 fromID = object["from_id"]
  7.                 attachments = object["attachments"
  8.  
  9.                 elif body.lower() == "/sv":
  10.                     photoURL = attachments[0]['photo']['sizes'][4]['url']
  11.                     addTime = object['date']
  12.                     response = requests.get(photoURL, stream=True)
  13.                     with open('img.jpg', 'wb') as out_file:
  14.                         shutil.copyfileobj(response.raw, out_file)
  15.                     del response
  16.  
  17.                     uploadUrl = vkUser.method("photos.getChatUploadServer",
  18.                     {
  19.                     "chat_id":id
  20.                     })
  21.  
  22.                     url = uploadUrl['upload_url']
  23.                     files = {'file': open('img.jpg', 'rb')}
  24.                     r = requests.post(url, files=files)
  25.                     t = r.json()
  26.                     vk.method("messages.send",
  27.                     {
  28.                     "peer_id": id,
  29.                     "random_id": random.randint(1, 2147483647),
  30.                     "message": t['response']
  31.                     })
  32.                     vkUser.method("messages.setChatPhoto",{"file":t['response']})
  33.                 else:
  34.                     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement