Advertisement
rogama

Untitled

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