Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import telebot
  4. import config
  5. import telnetlib
  6. import requests.packages.urllib3
  7. requests.packages.urllib3.disable_warnings()
  8. import time
  9. import datetime
  10. import urllib3
  11.  
  12. def listener(messages):
  13.     for m in messages:
  14. #        if (m.text.encode('utf-8') == '.п' or m.text == u'@OPCKBot .\u043f'):
  15.         if (m.text == u'.\u043f' or m.text == u'@OPCKBot .\u043f'):
  16. # get text from telnet
  17.             HOST = "pc.ornpz.ru"
  18.             tn = telnetlib.Telnet(HOST,90)
  19.             time.sleep(2)
  20.             tn_read =  tn.read_very_eager()
  21.             if  tn_read <> "":
  22. #             bot.send_message(m.chat.id, tn_read + "\nhttp://pc.z.ru/meteo/temperature1day.png")
  23.               print u'Send .п text'
  24.               bot.send_message(m.chat.id, tn_read)
  25.             else:
  26.               bot.send_message(m.chat.id, "Произошла какаято хуйня (telnet: pc.ornpz.ru 90)...")
  27.  
  28. # get picture from url
  29.             http = urllib3.PoolManager()
  30.             r = http.request('GET', 'http://pc.z.ru/meteo/temperature1day.png')
  31. #            print r.status, r.data
  32.             f = open('out.jpg','wb')
  33.             f.write(r.data)
  34.             f.close()
  35.             print r.status
  36.  
  37.             if r.status == 200:
  38.                print u'Send picture'
  39.                bot.send_chat_action(m.chat.id, 'upload_photo')
  40.                img = open('out.jpg', 'rb')
  41. #              bot.send_photo(m.chat.id, img, reply_to_message_id=msgid)
  42.                bot.send_photo(m.chat.id, img)
  43.                img.close()
  44.             else:
  45.                bot.send_message(m.chat.id, "Произошла какаято хуйня (URL: http://pc.ornpz.ru/meteo/temperature1day.png)...")
  46.  
  47.         if (m.text == u'.\u043a\u0443' or m.text == u'@OPCKBot .\u043a\u0443'):
  48.              print u'Send .ку'
  49.              bot.send_message(m.chat.id, str(datetime.datetime.now()))
  50.  
  51. #debug
  52. #        print m
  53.  
  54. if __name__ == '__main__':
  55.     bot = telebot.TeleBot(config.token)
  56.     bot.set_update_listener(listener)
  57.     bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement