def sendTemperatura(chat): chat.send(str(round(sum(temperatura)/len(temperatura),2))+" °C") def sendPressione(chat): chat.send(str(round(sum(pressione)/len(pressione),2))+" Pa") def sendLuce(chat): chat.send(str(round(sum(luce)/len(luce),2))+" Lux") def sendAltitudine(chat): chat.send(str(round(sum(altitudine) / len(altitudine), 2)) + " Metri") def LaunchBot(): bot.set_query( {"temperatura": sendTemperatura, "pressione": sendPressione, "luce": sendLuce, "altitudine": sendAltitudine}) bot.set_commands({"stats": SetBot}) bot.run() if __name__ == '__main__': bot = pzgram.Bot("893309177:AAHTL0ODM-2k-8KFN3kM1u46KdYZbFoMGWs") firstRun = True mqttThread = threading.Thread(target=mqttStart) mqttThread.setDaemon(True) mqttThread.start() botThread = threading.Thread(target=LaunchBot) botThread.start()
import pzgram from MQTT import * bot = pzgram.Bot("866748587:AAG0vayDiFIEt9ictxKLoLmyfD-2YE0U2WE") message = 'Bot Telegram che permette di visualizzare i valori rilevati dal Broker Calvino in diversi momenti: ' error_message = 'Il valore di temperatura non è stato ancora rilevato' ist = pzgram.create_button("istantaneo", "istantaneo") min_1 = pzgram.create_button("1 minuto", "1 minuto") min_10 = pzgram.create_button("10 minuti", "10 minuti") h_1 = pzgram.create_button("1 ora", "1 ora") k = [[ist, min_1], [min_10, h_1]] keyboard = pzgram.create_inline(k) def start(chat): global message, keyboard chat.send(message, reply_markup=keyboard) def get_istant(chat): global keyboard, error_message if not listaFinale[0]: chat.send(error_message) else: chat.send("Il valore di temperatura istantaneo è: {}".format(listaFinale[0])) start(chat) def get_min1(chat): global keyboard, error_message
import pzgram import request import urllib bot = pzgram.Bot("883446648:AAHGWLcnWooHtKjxk43isvh_2Y3k8kGAz6o") def SetBot(chat): button1 = pzgram.create_button("Temperatura", data="temperatura") button2 = pzgram.create_button("Pressione", data="pressione") button3 = pzgram.create_button("Luce", data="luce") button4 = pzgram.create_button("Altitudine", data="altitudine") k = [[button1, button2, button3, button4]] keyboard = pzgram.create_inline(k) chat.send( "Bot per il controllo remoto dei dati dei sensori della scuola Calvino: " ) chat.send("Seleziona un dato da controllare: ", reply_markup=keyboard) def sendTemperatura(chat): chat.send(str(round(sum(temperatura) / len(temperatura), 2)) + " °C") def sendPressione(chat): chat.send(str(round(sum(pressione) / len(pressione), 2)) + " Pa")
import pzgram import requests import time bot = pzgram.Bot("745277106:AAGJr1oJ8O0Si5tG5lapuWVjKkuLYGMqlJo") def ricerca(chat, message): chat.send(">>Ricerca valori...") time.sleep(3) def valori_istantanei(chat, message): temperatura = "temperatura istantanea" altitudine = "altitudine istantanea" pressione = "pressione istantanea" luminosita = "luminosita istantanea" ricerca(chat, message) chat.send(temperatura) chat.send(altitudine) chat.send(pressione) chat.send(luminosita) def valori_min_1(chat, message): temperatura = "temperatura di 1 minuto" altitudine = "altitudine di 1 minuto" pressione = "pressione di 1 minuto" luminosita = "luminosita di 1 minuto" ricerca(chat, message) chat.send(temperatura) chat.send(altitudine)
import pzgram import re from pytube import YouTube bot = pzgram.Bot("590932411:AAGS3ri3itZXYlgylWIZBBX1LJ7TivzHrH4") yt = {} filtro = {} filename = 1 def scelta(chat): chat.send("inserisci il link") bot.set_next(chat, recivelink) def recivelink(chat, message): global yt yt[chat.id] = YouTube(message.text) b1 = pzgram.create_button("audio", "downloadcanzone") b2 = pzgram.create_button("video", "downloadvideo") k = pzgram.create_inline([[b1, b2]]) chat.send("il link mi riporta la canzone: " + yt[chat.id].title + "\n Solo audio o video?", reply_markup=k) def qualita(query, message, data): global filtro, yt if data == "downloadcanzone": filtro[message.chat.id] = "only_audio"
import pzgram import rss import db import transmission from config import bot_key, owner_id bot = pzgram.Bot(bot_key) ownerId = owner_id def torrent_command(chat): torrent = transmission.get_torrent_status() text = "" for t in torrent: if t["error"]: text += "‼️ " if t["status"] == "Downloading": text += "*Name*: " + t["name"][:30] + "\n *Status*: ⏬ *" + t["perc"] \ + "*\n *DownSpeed*: " + t["dws"] + "\n *ETA*: " + t["eta"] + "\n\n" elif t["status"] == "Seeding": text += "*Name*: " + t["name"][:30] + "\n *Status*: ⏫ " + t["ups"] + "\n\n" elif t["status"] == "Up & Down": text += "*Name*: " + t["name"][:30] + "\n *Status*: ⏬⏫ *" + t["perc"] \ + "*\n *DS:* " + t["dws"] + " *US:*" + t["ups"] + "\n *ETA*: " + t["eta"] + "\n\n" else: text += "*Name*: " + t["name"][:30] + "\n *Status*: " + t["status"] + " " + t["perc"] + "\n\n" chat.send(text, parse_mode="markdown") def add_command(chat):
choice = str(insta) misura = "Misura istantanea: " elif data == "choice2": choice = str(unmin) misura = "Media temperatura ultimo minuto: " elif data == "choice3": choice = str(diecimin) misura = "Media temperatura ultimi dieci minuti: " elif data == "choice4": choice = str(unora) misura = "Media temperatura ultima ora: " pool_message += "\n" + misura + choice message.edit(pool_message, reply_markup=pool_keyboard) #SETTAGGI BOT E RELATIVI BOTTONI bot = pzgram.Bot("751724127:AAFlji-_pV1zwJfIG8ocwL9ei1DIMW7AVB8") pool_message = "" button1 = pzgram.create_button("Istantanea", "choice1") button2 = pzgram.create_button("1 m", "choice2") button3 = pzgram.create_button("10 m", "choice3") button4 = pzgram.create_button("1 h", "choice4") k = [[button1, button2, button3, button4]] pool_keyboard = pzgram.create_inline(k) commands = {"start": pool_command} bot.set_commands(commands) queries = { "choice1": catch_results, "choice2": catch_results, "choice3": catch_results, "choice4": catch_results
import pzgram bot = pzgram.Bot("BOTKEY") def scrivi_riga(messaggio): file = open("diario.txt", "a") file.write("\n" + messaggio) file.close() def leggi_riga(numero_riga): file = open("diario.txt", "r") righe = file.readlines() return righe[numero_riga] def registra_command(message, chat): # /registra Frase da registrare testo = message.text testo = testo.replace("/registra ", "") scrivi_riga(testo) chat.send("Messaggio Registrato!") def visualizza_command(chat, message): # /visualizza 2 testo = message.text numero_riga = int(testo.replace("/visualizza ", "")) riga = leggi_riga(numero_riga) chat.send(riga)
import pzgram, pickle, threading, subprocess, decimal bot = pzgram.Bot("706070524:AAGA-aIaEnFaZh_7Q1rxooqxvJFTYUJCRQU") CID = 238796511 #_______START_______ def start_command(chat): keyboard = pzgram.create_keyboard([["/Temperatura", "/Luce"], ["/Altitudine", "/Pressione"]]) chat.send("Select a command", reply_markup=keyboard) #_______TMP_______ def show_temp(chat): keyboard = pzgram.create_keyboard([["/InstantTmp", "/LastMinTmp"], ["/Last10MinTmp", "/LastHourTmp"]]) chat.send("Select a command", reply_markup=keyboard) def sendInstantTmp(chat): global listaDati chat.send("{} C°".format(listaDati[-1]["temperatura"])) def sendLastMinuteTmp(chat): global listaDati, lockDati
import pzgram from MQTT import * #with open("file.txt","r") as file: # token=file.readline() bot = pzgram.Bot("713980055:AAFVGg-LrMkba3K6MgbaHej1t4zcuzwGbns") #MESSAGES msg = "Choose one of the following buttons\n" err_msg="Sorry, the time of execution is less than the specified time..." ist=pzgram.create_button("ist","ist") min_1=pzgram.create_button("1 min","1 min") min_10=pzgram.create_button("10 min","10 min") h_1=pzgram.create_button("1 h","1 h") k =[[ist, min_1], [min_10,h_1]] keyboard=pzgram.create_inline(k) #CONTATORE cont=1 def start(chat): global msg, keyboard # Send the pool message, attaching the inline keyboard chat.send(msg, reply_markup=keyboard) def get_istant(query, data, message, chat): global keyboard, err_msg, msg, cont if listaFinale[0] == None: chat.send(err_msg)
import pzgram from datetime import datetime, timedelta import SQL_function import apiKey import useful_function bot = pzgram.Bot(apiKey.apiBot) # IDEA # TODO: MORE EMOJI!!!!! # Subjects Emoji def start_command(chat, message): chat.send('Hi, *'+message.sender.first_name+'*\n' 'Welcome to schoolDiaryBot, \nUse the keyboard to view all the possible commands\n' 'This is an [open-source bot](http://github.com/infopz/pzGram_schoolDiary) by @infopz\n' 'If you want more info about this bot visit [my site](http://infopz.hopto.org/schoolDiary/)', disable_preview=True) # START /new FUNCTION def new_test(chat, shared): chat.send('Select a date:', reply_markup=shared['keyboards']['this_m_test']) shared['cache'] = {'conv_dict': shared['keyboards']['this_m_c']} shared['status'] = 'newTest' def new_homework(chat, shared):
import classeviva import time import pzgram from pyDes import * import sql_functions import key bot = pzgram.Bot(key.bot_key) def check_new_vote(u): s0 = classeviva.Session() password = triple_des(key.master_key).decrypt(u[2], padmode=2).decode('utf-8') s = login(s0, u[1], password) if s == False: send_not_valid(u[0]) return False old_grades = sql_functions.get_old_grades(u[0]) old_grades_list = [] for i in old_grades: old_grades_list.append(i[1]) newgrades = get_grades(s) nuovi_voti = [] for g in newgrades: if g['evtId'] not in old_grades_list: sql_functions.register_vote(u[0], g['evtId'], g['decimalValue'], g['subjectDesc'], g['evtDate']) nuovi_voti.append(g) return nuovi_voti
def start(): bot = pzgram.Bot("662598430:AAFGsERMnrQdi1ugXjT5E6cpEIeiNDitlv0") bot.set_query({"instantanea" : instantanea , "Unminuto" : Unminuto, "Dieciminuti" : Dieciminuti, "Unora" : Unora}) bot.set_commands({"start": inizio}) bot.set_commands({"bottoni" : bottoni}) bot.run()