Advertisement
rogama

Bajar foto

Oct 4th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import telebot
  2. import sys
  3. import time
  4. import os
  5. import requests
  6. import shutil
  7.  
  8. API_TOKEN = "138599838:AAH_vFfAUqsIo71E3l6Ciqra0ZdBQ8yjHu4"
  9.  
  10. bot = telebot.TeleBot("138599838:AAH_vFfAUqsIo71E3l6Ciqra0ZdBQ8yjHu4")
  11. administrador = 22784456
  12. bot.send_message(administrador, "Bot started.")
  13.  
  14. def listener(msg):
  15.     for m in msg:
  16.         if m.content_type == "photo":
  17.             cid = m.chat.id
  18.             print cid
  19.             fileid = m.photo[0].file_id
  20.             print fileid
  21.             file_info = bot.get_file(fileid)
  22.             print file_info
  23.            
  24.             with open("photo3.jpg","wb",0) as download:
  25.                 filedown = requests.get('https://api.telegram.org/file/bot{0}/{1}'.format(API_TOKEN, file_info.file_path))
  26.                 for chunk in filedown.iter_content():
  27.                     download.write(chunk)
  28.                 download.close()
  29.         if m.content_type == "text":
  30.             cid = m.chat.id
  31.             bot.send_message(cid, "BOT OK!")
  32.            
  33.  
  34.  
  35. bot.set_update_listener(listener)
  36. bot.polling(none_stop=False,interval=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement