Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import telebot
- import config
- import telnetlib
- import requests.packages.urllib3
- requests.packages.urllib3.disable_warnings()
- import time
- import datetime
- import urllib3
- def listener(messages):
- for m in messages:
- # if (m.text.encode('utf-8') == '.п' or m.text == u'@OPCKBot .\u043f'):
- if (m.text == u'.\u043f' or m.text == u'@OPCKBot .\u043f'):
- # get text from telnet
- HOST = "pc.ornpz.ru"
- tn = telnetlib.Telnet(HOST,90)
- time.sleep(2)
- tn_read = tn.read_very_eager()
- if tn_read <> "":
- # bot.send_message(m.chat.id, tn_read + "\nhttp://pc.z.ru/meteo/temperature1day.png")
- print u'Send .п text'
- bot.send_message(m.chat.id, tn_read)
- else:
- bot.send_message(m.chat.id, "Произошла какаято хуйня (telnet: pc.ornpz.ru 90)...")
- # get picture from url
- http = urllib3.PoolManager()
- r = http.request('GET', 'http://pc.z.ru/meteo/temperature1day.png')
- # print r.status, r.data
- f = open('out.jpg','wb')
- f.write(r.data)
- f.close()
- print r.status
- if r.status == 200:
- print u'Send picture'
- bot.send_chat_action(m.chat.id, 'upload_photo')
- img = open('out.jpg', 'rb')
- # bot.send_photo(m.chat.id, img, reply_to_message_id=msgid)
- bot.send_photo(m.chat.id, img)
- img.close()
- else:
- bot.send_message(m.chat.id, "Произошла какаято хуйня (URL: http://pc.ornpz.ru/meteo/temperature1day.png)...")
- if (m.text == u'.\u043a\u0443' or m.text == u'@OPCKBot .\u043a\u0443'):
- print u'Send .ку'
- bot.send_message(m.chat.id, str(datetime.datetime.now()))
- #debug
- # print m
- if __name__ == '__main__':
- bot = telebot.TeleBot(config.token)
- bot.set_update_listener(listener)
- bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement