Skip to content

Instantly share code, notes, and snippets.

@hitesh83
Last active August 20, 2018 08:28
Show Gist options
  • Save hitesh83/f54c74037e9e3aff4c43de51870031f8 to your computer and use it in GitHub Desktop.
Save hitesh83/f54c74037e9e3aff4c43de51870031f8 to your computer and use it in GitHub Desktop.
Installing Telebot on RPi
sudo apt-get install python-pip -y
sudo pip install telepot
git clone https://github.com/AndrewFromMelbourne/raspi2png/
sudo cp -a raspi2png/raspi2png /usr/local/bin
sudo apt-get install imagemagick -y
sudo nano telebot.sh
<python script as below--start>
import time
import random
import datetime
import subprocess
import os
import telepot
from telepot.loop import MessageLoop
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print 'Got command: %s' % command
if command == '/bctdf':
df = subprocess.check_output(['df', '-h'])
print '', df
bot.sendMessage(chat_id, str(df))
elif command == '/bctfree':
free = subprocess.check_output(['free','-h'])
print '', free
bot.sendMessage(chat_id, str(free))
elif command == '/bctdate':
date = subprocess.check_output(['date'])
print '', date
bot.sendMessage(chat_id, str(date))
elif command == '/bctcpu':
cpu = subprocess.check_output(['cat', '/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq'])
print '', cpu
bot.sendMessage(chat_id, 'CPU Freq='+str(cpu))
elif command == '/bctuptime':
uptime = subprocess.check_output(['uptime', '-p'])
print '', uptime
bot.sendMessage(chat_id, str(uptime))
elif command == '/bctreboot':
bot.sendMessage(chat_id, 'Rebooting')
time.sleep(10)
os.system('sudo shutdown -r now')
elif command == '/bcttmp':
tmp = subprocess.check_output(['/opt/vc/bin/vcgencmd', 'measure_temp'])
print '', tmp
bot.sendMessage(chat_id, str(tmp))
elif command == '/bctvw':
bot.sendMessage(chat_id, 'Capturing Screen Shot from BCT VideoWall, Please wait 10sec ...')
os.system('/usr/local/bin/raspi2png -p /home/pi/picam/screenshot.png')
time.sleep(10)
os.system('convert /home/pi/picam/screenshot.png -crop 720x360+0+0 /home/pi/picam/screen.png')
time.sleep(10)
bot.sendPhoto(chat_id=chat_id, photo=open('/home/pi/picam/screen.png'))
bot = telepot.Bot('TELEGRAM BOT API KEY HERE')
MessageLoop(bot, handle).run_as_thread()
print 'I am listening ...'
while 1:
time.sleep(10)
@hitesh83
Copy link
Author

import time
import random
import datetime
import subprocess
import os
import telepot
from telepot.loop import MessageLoop

def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == 'photo':
bot.download_file(msg['photo'][-1]['file_id'], './file.png')
elif content_type == 'text':
with open ('./id.txt','w') as f:
f.write(str(msg['text']))
bot.sendMessage(msg['chat']['id'],"ID saved")
chat_id = msg['chat']['id']
command = msg['text']

print 'Got command: %s' % command

if command == '/ddr2df':
    df = subprocess.check_output(['df', '-h'])
    print '', df
    bot.sendMessage(chat_id, str(df))
elif command == '/ddr2free':
    free = subprocess.check_output(['free','-h'])
    print '', free
    bot.sendMessage(chat_id, str(free))
elif command == '/ddr2play':
    play = subprocess.check_output(['ls','/home/pi/media'])
    print '', play
    bot.sendMessage(chat_id, str(play))
elif command == '/ddr2date':
date = subprocess.check_output(['date'])
print '', date
bot.sendMessage(chat_id, str(date))
elif command == '/ddr2cpu':
cpu = subprocess.check_output(['cat', '/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq'])
print '', cpu
bot.sendMessage(chat_id, 'CPU Freq='+str(cpu))
elif command == '/ddr2uptime':
uptime = subprocess.check_output(['uptime', '-p'])
print '', uptime
bot.sendMessage(chat_id, str(uptime))
elif command == '/ddr2reboot':
bot.sendMessage(chat_id, 'Rebooting')
time.sleep(10)
reboot = subprocess.Popen(['reboot'])
elif command == '/ddr2tmp':
tmp = subprocess.check_output(['/opt/vc/bin/vcgencmd', 'measure_temp'])
print '', tmp 
bot.sendMessage(chat_id, str(tmp))
elif command == '/ddr2':
    bot.sendMessage(chat_id, 'Capturing Screen Shot from Dadar FOB VideoWall, Please wait 30sec ...')
    os.system('/usr/local/bin/raspi2png -p /home/pi/picam/screen.png')
    time.sleep(10)
os.system('convert /home/pi/picam/screen.png -crop 518x310+0+0 /home/pi/picam/screenshot.png')
    time.sleep(10)
    bot.sendPhoto(chat_id=chat_id, photo=open('/home/pi/picam/screenshot.png'))

bot = telepot.Bot(TOKEN')

MessageLoop(bot, handle).run_as_thread()

print 'I am listening ...'

while 1:
time.sleep(10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment