In [ ]:
import pandas as pd
import datetime

df = pd.read_csv('contracts.csv', header=None)
df.columns = ['Contract_Name', 'Contract_Value','Contract_Renewal']

now = datetime.date.today()

def format_date(row):
    year = int(row['Contract_Renewal'][7:])
    month = int(row['Contract_Renewal'][4:6])
    day = int(row['Contract_Renewal'][:3])
    date = datetime.date(year, month, day)
    return date-now

def status_calc(row):
    val_to_check = int(str(row['days_until']).split(' ')[0])
    if val_to_check < 1:
        return 'overdue'
    elif val_to_check >0 and val_to_check < 60:
        return 'action now'
    else:
        return 'ok'

df['days_until'] = df.apply(format_date, axis=1)
df['status'] = df.apply(status_calc, axis=1)

rows = df.values.tolist()

#convert to html
email = " Contracts to review: {df} Thanks"
email = email.format(df=df.to_html())

#os.system("echo \"export SENDGRID_API_KEY='key0'\" > sendgrid.env")
#os.system("echo \"sendgrid.env\" >> .gitignore")
#os.system("source ./sendgrid.env")

import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

message = Mail(
    from_email='from_mail',
    to_emails='to_mail',
    subject='Contract Renewal Status',
    html_content= email)

sg = SendGridAPIClient(os.environ.get('api_key'))
response = sg.send(message)
print(response.status_code, response.body, response.headers)