import datetime
import pymysql
import pandas as pd

def doctor():
    date_str = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y%m%d")
    date_tmp = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
    # sql = "select distinct doctor_id from statistic_doctor_rank_factor where partition_date = '{}'".format(date_str)
    # doctor_list = pd.DataFrame(list(result))[0].values.tolist()

    sql = "select d.doctor_id,d.service_exposure_pv_30,d.service_ctr_30,d.expert_exposure_pv_30,d.expert_pv_30," \
    "b.merchant_id," \
    "m.doctor_ad_money_30_days,m.expand_rechange_amount_30,m.service_pv_30,m.expert_pv_30,m.organization_pv_30," \
    "budan.budan_payment_30_days " \
    "from statistic_doctor_rank_factor d " \
    "left join hippo_merchantrelevance b on d.doctor_id = b.doctor_id " \
    "left join statistic_merchant_rank_factor m on b.merchant_id = m.merchant_id " \
    "left join al_meigou_service_smart_rank_budan_payment budan on b.merchant_id = budan.merchant_id limit 6 " \
    "where d.partition_date = '{}' and m.partition_date = '{}' " \
    "and budan.stat_date = '{}'".format(date_str,date_str,date_tmp)
    print(sql)
    db = pymysql.connect(host='172.16.30.143', port=3306, user='work', passwd='BJQaT9VzDcuPBqkd', db='zhengxing')
    cursor = db.cursor()
    cursor.execute(sql)
    result = cursor.fetchall()
    df = pd.DataFrame(list(result))
    print(df.head(6))


if __name__ == "__main__":
    doctor()

