如何用python显示mysql表到telegram bot的多条记录,并且只有特定的电话号码才能访问我的bot telegram

2024-04-29 15:56:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我还是python脚本的初学者。我想问一下名字, 我有了新的想法来监控我办公室的关键绩效指标,几乎完成了。但是有一个问题是我自己无法完成的。在

如何用python显示mysql表到telegram bot的多条记录,并且只有特定的电话号码才能访问我的bot telegram?在

这是我的剧本:

'如何将多条记录从mysql表显示到telegram bot'

def query(requ):
cursor = db.cursor()
sql = "SELECT * FROM monitor WHERE Tanggal LIKE '%" + str(requ.encode('utf-8')) + "%'"

try:
    cursor.execute(sql)
    # memecahkan hasil dari table
    results = cursor.fetchall()

    # memberikan hasil jika hasil sesuai sama tabel maka keluar sesuai hasil
    if len(results)>0:
        output = ''
        for row in results:
            Tanggal = row[0]
            DOWNTIME_PLN = row[1]
            RUN_GENSET = row[2]
            SHREDDER_MILL_DOWNTIME = row[3]
            SHREDDER_CRUMB_DOWNTIME = row[4]
            SHREDDER_CRUMB_AMPERE = row[5]
            has_trans = row[6]
            # Now print fetched result
            output = "Tanggal = %s, \nDOWNTIME_PLN = %d, \nRUN_GENSET = %s, \nSHREDDER_MILL_DOWNTIME = %s, \nSHREDDER_CRUMB_DOWNTIME=%s, \nSHREDDER_CRUMB_AMPERE=%s, \nhas_trans = %s" % \
            (Tanggal,DOWNTIME_PLN,RUN_GENSET,SHREDDER_MILL_DOWNTIME,SHREDDER_CRUMB_DOWNTIME,SHREDDER_CRUMB_AMPERE,has_trans)
            print (Tanggal,DOWNTIME_PLN,RUN_GENSET,SHREDDER_MILL_DOWNTIME,SHREDDER_CRUMB_DOWNTIME,SHREDDER_CRUMB_AMPERE,has_trans)
    else:
        output = 'No word in my dic'
except:
    output = 'error'
return output

“如何只有特定的电话号码才能访问我的机器人电报?”在

^{pr2}$

谢谢:)


Tags: transoutputbotmillcursorrowtelegramdowntime