import pymysql
import pandas as pd

def getConn():
    # 从数据库的表里获取数据

    db = pymysql.connect(host='172.16.50.175', port=3306, user='doris', passwd='o5gbA27hXHHm',
                         db='doris_olap')
    # cursor = db.cursor()
    # cursor.execute(sql)
    return db


if __name__ == '__main__':
    sql = """
        select day_id,service_id,service_all_first_browse_num_d,service_all_preciseexpose_num_d,service_cpc_expend_recharge_amount_d
     ,service_add_cart_click_num_d,service_message_click_num_d,service_buy_click_num_d,service_validate_order_commission_non_doctor_d 
     from sl_strategy_pt_sv_servicesmartrank_d where day_id='20210711'
     """

    conn = getConn()
    df = pd.read_sql_query(sql,conn)
    print(df.head(10))
    print(df.count())
    df.to_excel("ecpm_data.xlsx")
