
# 将不同时间的add 的hold信息合并在一起 分析他们的变化 找出庄家地址/分析庄家变化 
import pandas as pd
import sys

import datetime
import pytz
from openpyxl.styles import *
# from openpyxl.styles.colors import RED, GREEN
arr_file = []
merged_df = None
 
token_add = ""


def makeurl( url,url_show):
    return '=HYPERLINK("{}","{}")'.format(url,  url_show)




def get_nowdate():

    timestamp = datetime.datetime.now().timestamp()
    # print(timestamp)
    dt = datetime.datetime.fromtimestamp(timestamp)
    tz = pytz.timezone('Asia/Shanghai')
    normal_time_str = dt.astimezone(tz).strftime('%Y-%m-%d %H:%M:%S')
    time_str = dt.astimezone(tz).strftime('%m%d%H%M')
    return time_str

 
 
arr_df = []
arr_sheet_names =[]
merged_hodlers_excel_kuangjia_file = ""
merged_special_add_hold_info_file=""
token_add = '5puhwnyz2Tv8jSmmBD5DSqCwFVXwwPGZacymM7DQpump'
def merge_swap_df_fun_02():
    global arr_sheet_names
    global merged_hodlers_excel_kuangjia_file , merged_special_add_hold_info_file
    global arr_df
    merged_hodlers_excel = pd.ExcelFile(merged_hodlers_excel_kuangjia_file)
    arr_sheet_names = list(merged_hodlers_excel.sheet_names)
    arr_sheet_names.pop(0)

    merged_df= pd.read_excel(merged_special_add_hold_info_file,engine='openpyxl')
    merged_df["gmgn"] = merged_df.apply(lambda ser: makeurl(
    f"https://gmgn.ai/sol/token/{token_add}?tab=activity&maker={ser['holder_owner']}" , "gmgn" ), axis=1)
    merged_df["defined"] = merged_df.apply(lambda ser: makeurl(
     f"https://www.defined.fi/sol/{token_add}?maker={ser['holder_owner']}" , "defined" ), axis=1)
    
  
    
    arr_df.append(merged_df)
    
    for sheet_name in arr_sheet_names:
        holder_df = merged_hodlers_excel.parse(sheet_name=sheet_name)

        cur_df = merged_df[  merged_df['holder_owner'].isin(holder_df['holder_owner'])].reset_index(drop=True)
        cur_df = cur_df.set_index('holder_owner').reindex(holder_df['holder_owner']).reset_index()

        arr_df.append(cur_df)   


def save_to_excel(out_excel):
    global    arr_df ,arr_sheet_names
    with pd.ExcelWriter(out_excel) as writer:
        for idx ,cur_df in enumerate(arr_df):
            sheet_name = ''

            if idx==0:
                sheet_name = 'Sheet1'
            else:
                sheet_name = arr_sheet_names[idx-1]
            cur_df.to_excel(writer, sheet_name=sheet_name, index=False)


def makeurl( url,url_show):
    return '=HYPERLINK("{}","{}")'.format(url,  url_show)

if __name__ == "__main__":
  
    merged_hodlers_excel_kuangjia_file = '003_merge_holders_excel_kuangjia.xlsx'
    merged_special_add_hold_info_file = '002_merge_special_add_hold_info.xlsx'
    time_str = get_nowdate()
    out_excel =f'004_special_add_holders_excel_final_{time_str}.xlsx'
    
    merge_swap_df_fun_02()
    save_to_excel(out_excel)
