import pymysql
import csv
from O365 import Message
import pandas
import sys
#Database Connection
connection = pymysql.connect(host="localhost", user="root", passwd="nishu123", database="last")
cursor = connection.cursor()
query = "SELECT merchant.m_id,merchant.m_name, sum(case when status='captured' then 1 else 0 end)/count(*)*100 as Success_Per ,merchant.status,merchant.issuer, merchant.payment_gateway, merchant.amount, waste.threshold_value, waste.email_id FROM merchant INNER JOIN waste ON merchant.m_name = waste.m_name group by m_name;"
df = pandas.read_sql(query, connection)
connection.close()
df.to_csv('yo.csv')
print('Done')
def findmail():
print("Entering IN")
db = pymysql.connect(host="localhost", user="root", passwd="nishu123", database="last")
cur = db.cursor()
query = "select email_id from waste where m_name='m_name';"
data=cur.execute(query)
data=cur.fetchall()
print(data)
def sendemail():
o365_auth = ("username", "password")
m = Message(auth=o365_auth)
m.setRecipients(data)
m.setSubject('Performance Decreased')
m.setBody('Hi...')
m.sendMessage()
sendemail()
with open('yo.csv') as csvfile:
csvfile.seek(0, 0)
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
if row[3] < row[8]:
findmail()
else:
print("everything is fine")
我想通过使用Email_id
从csv
文件中获取匹配值来从SQL中找到Pandas
值。 csv
文件包含列name =m_id,m_name,status,successrate,thresholdvalue
,
当我将successrate
与阈值进行比较时
在这段代码中,当游标转到查询部分的findmail函数时,它不会重试任何内容。