# -*- coding:utf-8 -*-
# Author: WuKong

import sys
import datetime
import itertools
import pandas as pd
from sqlalchemy import create_engine
import multiprocessing as mtp
import os

reload(sys)
sys.setdefaultencoding('utf8')

engine_audit = create_engine(
    'mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/audit?charset=utf8',
    echo=True)

engine_payment_center = create_engine(
    'mysql+mysqldb://bowang:in78u6ytgbhj56r@192.168.4.6:8066/payment_center?charset=utf8',
    echo=False)

engine_xyqb = create_engine(
    'mysql+mysqldb://bowang:in78u6ytgbhj56r@192.168.4.6:8066/xyqb?charset=utf8',
    echo=False)

sql_audit_loan = """
SELECT ref_id ,loan_id,contract_loan_amount,DATE(loan_paid_at) FROM loan_manifest WHERE funding_code=420
"""

sql_xyqb_loan = """
SELECT loan_application_history_id loan_id,DATE(loan_paid_at),contract_loan_amount FROM loan_application_manifest_history WHERE funding_corp_id =420 AND transaction_status in (2,5) AND loan_paid_at<"2017-11-01"
"""
df_audit_loan = pd.read_sql(sql=sql_audit_loan,con=engine_audit)
df_xyqb_loan = pd.read_sql(sql=sql_xyqb_loan,con=engine_xyqb)