Commit 4c59e36c authored by Alessandro Cumin's avatar Alessandro Cumin 🤸🏾

primo commit

## python example telegram bot
import sys
import time
import random
import datetime
import telepot
import re
import string
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
print 'Got command: %s' % command
if command == '/roll':
bot.sendMessage(chat_id, random.randint(1,6))
elif command == '/time':
bot.sendMessage(chat_id, str(
elif command == '/help':
bot.sendMessage(chat_id, str('/roll: simula un lancio di dado, generando un numero random fra 1 e 6\n /time: restituisce il timestamp attuale\n /help: elenca i comandi disponibili\n /ip: mostra ultimo ip che ha contattato la raspberry'))
elif command == '/ip':
with open('/media/hd/www/dati.txt') as f:
righe = 0
data = f.readlines()
for linea in data:
righe = righe + 1
tail = data[-1:]
s = str(tail)
ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', s )
messaggio = str(righe) + str(ip)
bot.sendMessage(chat_id, str(messaggio))
bot = telepot.Bot('947870401:AAFiVQvORT499oV4lFh8cXYI346qc7tj_ms')
print 'I am listening...'
while 1:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment