1. 程式人生 > 實用技巧 >pyhon,統計一個字串,在一個文本里面的個數,寫查慢sql時用到的

pyhon,統計一個字串,在一個文本里面的個數,寫查慢sql時用到的

直接貼程式碼

用到的方法,就是 count 預設是從0開始,到最後結束

https://www.runoob.com/python/att-string-count.html

#線上慢sql報警提示
def check_mansql():
today_url="http://10.1.21.104/index.php"
#history_url="http://10.1.21.104/index.php?begin=2020-08-10"
response=requests.request("get",url=today_url,verify=False)
list=["booking_avatar","registration_avatar","cooperation_avatar","patientsignin_avatar","exhibition_avatar","evection_avatar","cosmetology_avatar","sickmanage_avatar","comment_avatar"]
list_sql=[]
for i in range(0,len(list)):
a=list[i]
a_counts=response.text.count(a)
if a_counts > 1:
mansqltixing=a+"有線上慢sql,連結:http://10.1.21.104"+" "
list_sql.append(mansqltixing)
content = "".join(list_sql)
mentioned_mobile_list = ['18210466329']
send_rebot(msgtype="text", content=content, mentioned_mobile_list=mentioned_mobile_list)