salve, come si può intuire dal titolo del posto, ho un problema con un bot, questo funziona solo sul telefono che lo avvia per primo, gli altri non ricevono nulla, allego il codice per contestualizzare, in poche parole il bot segna un allarme quando sul database legge un valore più alto della soglia, funziona bene unico problema una volta chiamato con /start dal primo dispositivo, sugli altri non va.
#!/usr/bin/env python
import pymysql
import telepot
import time
#TOKEN = '691375125:AAGgcPYiQoTkHoABP-qLwNOnOYARo7QgnG0'
#bot = telepot.Bot(TOKEN)
def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
while True:
db = pymysql.connect("localhost","root","root","pippo")
cursor = db.cursor()
cursor.execute("select count(*) from prova where eta > 18")
((data,),) = cursor.fetchall()
if data > 0:
print("allarme ci sono {} maggiorenni".format(data))
bot.sendMessage(chat_id, 'allarme')
time.sleep(5)
db.close()
TOKEN = '691375125:AAGgcPYiQoTkHoABP-qLwNOnOYARo7QgnG0'
bot = telepot.Bot(TOKEN)
bot.message_loop(on_chat_message)
print ('Listening ...')
import time
while 1:
time.sleep(10)
#!/usr/bin/env python
import pymysql
import telepot
import time
#TOKEN = '691375125:AAGgcPYiQoTkHoABP-qLwNOnOYARo7QgnG0'
#bot = telepot.Bot(TOKEN)
def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
while True:
db = pymysql.connect("localhost","root","root","pippo")
cursor = db.cursor()
cursor.execute("select count(*) from prova where eta > 18")
((data,),) = cursor.fetchall()
if data > 0:
print("allarme ci sono {} maggiorenni".format(data))
bot.sendMessage(chat_id, 'allarme')
time.sleep(5)
db.close()
TOKEN = '691375125:AAGgcPYiQoTkHoABP-qLwNOnOYARo7QgnG0'
bot = telepot.Bot(TOKEN)
bot.message_loop(on_chat_message)
print ('Listening ...')
import time
while 1:
time.sleep(10)