import pandas as pd
import pymysql
import datetime


def con_sql(db,sql):
    cursor = db.cursor()
    cursor.execute(sql)

    result = cursor.fetchone()
    print(result)
    print(result[0])
    db.close()
    return result


def get_ctr():
    db = pymysql.connect(host='172.16.40.158', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='jerry_prod')
    yesterday = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
    print(yesterday)
    sql = "select count(*) from data_feed_exposure_precise where stat_date = '{}'".format(yesterday)
    exposures = con_sql(db, sql)
    # sql = "select count(*) from data_feed_click where stat_date = '{}'".format(yesterday)
    # clicks = con_sql(db, sql)
    # print(exposures)
    # print(clicks)
    # print(exposures/clicks)




if __name__ == "__main__":
    get_ctr()