im new to python and trying to understand how to send email alerts. I have a csv file, the below is the dataframe for it:
,Latitude,Longtitude,LocationKey,MatchDescription
0,38.67694301003448,-77.7429029707531,609751,rooftop
1,29.372805012097956,-98.53188396363142,609750,rooftop
2,37.72961100923345,-122.38610096386918,609749,rooftop
3,42.509437395496974,-70.86884298867957,609748,rooftop
4,was not geocoded,rooftop
5,25.982770005233007,-80.16985001050395,609745,place
everyday this particular csv regenerates with new values, however, occasionally, I get the above error saying was not geocoded. I want a script that sends me an email alert each time that string shows up in this generated csv.
import pandas as pd
import smtplib
from email.message import EmailMessage
df = pd.read_csv('StgDimLocationEsri.csv')
cols_to_check = ["Latitude","Longtitude","LocationKey"]
def email_alert(subject,body,to):
msg = EmailMessage()
msg.set_content(body)
msg['subject'] = subject
msg['to'] = to
# msg['from'] = from
user = "xx@gmail.com"
msg['from'] = user
password = "clqdgqyfrleisynd"
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(user,password)
server.send_message(msg)
server.quit()
if __name__ == '__main__':
email_alert("Hey","Error","yy.t@cfi.com")
for col in cols_to_check:
if not pd.to_numeric(df[col], errors='coerce').all():
email_alert()
The problem is that i am receiving an email even if there are only numerics under these columns. I tried to replace the was not geocoded with numericals and i still got the error email