# 将dune 上 special的add 的swap和transfer合并在一起
import pandas as pd
import sys
import re
import datetime
import pytz

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
def utc_2_shanghaidate(df , utc_time_col ):
# 将字符串转换为UTC时间的datetime对象
    df[utc_time_col] = pd.to_datetime(df[utc_time_col], utc=True)
    # 定义UTC+8时区
    utc_plus_8 = pytz.timezone('Asia/Shanghai')
    # 转换为UTC+8时间
    # df['shanghai_date'] = df['shanghai_date'].dt.tz_convert(utc_plus_8)
    # # 提取时间字符串
    # df['shanghai_date'] = df['shanghai_date'].dt.strftime('%Y-%m-%d %H:%M')
    df[utc_time_col] = df[utc_time_col].dt.tz_convert(utc_plus_8)
    # 提取时间字符串
    df[utc_time_col] = df[utc_time_col].dt.strftime('%Y-%m-%d %H:%M')
    return df
 


def main():
    global file_merge_swap_transfer_row
    df_swap_row = pd.read_excel(file_merge_swap_transfer_row )
    df_swap_row= df_swap_row[df_swap_row['trader_id'].isin(arr_trader)].reset_index(drop=True)
    df_swap_row['block_time'] = pd.to_datetime(df_swap_row['block_time'])
    
    
    df_swap_row =df_swap_row[
 (   df_swap_row['block_time']>pd.Timestamp(start_datetime) )
    & (df_swap_row['block_time']<=pd.Timestamp(end_datetime))    
    ].reset_index(drop=True)

    df_swap_row["oklink"] = df_swap_row.apply(lambda ser: makeurl(
     f"https://www.oklink.com/zh-hans/sol/tx/{ser['tx_id']}" , "oklink" ), axis=1)

    df_swap_row["scan"] = df_swap_row.apply(lambda ser: makeurl(
     f"https://solscan.io/tx/{ser['tx_id']}" , "scan" ), axis=1)
    
    
    df_swap_row.to_excel(  f'006_merge_swap_transfer_total_info_{str_start}-{str_end}.xlsx'  ,index=False)
    
 
    return

start_datetime =   '2025-01-09 01:00:00'
end_datetime = '2025-01-16 02:00:00'
 
str_start =  re.split(r'[- :]', start_datetime)
str_start =  str_start[1]+str_start[2]+ '日'+ str_start[3]+str_start[4]

str_end =  re.split(r'[- :]', end_datetime)
str_end =  str_end[1]+str_end[2]+ '日'+ str_end[3]+str_end[4]

df_all_holders = pd.read_excel('001_all_holders.xlsx')
df_all_holders=df_all_holders.dropna(subset=['holder_owner'])

arr_trader = [
 
]
arr_trader  = df_all_holders['holder_owner'].tolist()

file_merge_swap_transfer_row  =  '005_merge_swap_transfer_row.xlsx'



 
main()