59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
from models.tg_models import TelegramAccount
|
|
from models.tg_phone_devices import TgPhoneDevices
|
|
from models.wallet_okx import WalletAddressOkx
|
|
|
|
|
|
if __name__ == '__main__':
|
|
project_name = "caps"
|
|
|
|
try:
|
|
# 批量查询已登录 Telegram 的账户
|
|
logged_in_accounts = TelegramAccount.select().where(TelegramAccount.is_logged_in_telegram == 1)
|
|
|
|
# 提取所有已登录账户的 ld_name
|
|
all_ld_names = [account.ld_name for account in logged_in_accounts]
|
|
|
|
# 查询 session 表的电话号码
|
|
tg_infos = TgPhoneDevices.select().where(TgPhoneDevices.is_valid_session == 1)
|
|
|
|
# 合并电话号码
|
|
all_ld_names.extend([tg_info.phone for tg_info in tg_infos if tg_info.phone not in all_ld_names])
|
|
|
|
print(len(all_ld_names))
|
|
|
|
# 批量查询已分配给该项目的 ld_name
|
|
assigned_ld_names = [okx.ld_name for okx in WalletAddressOkx.select(WalletAddressOkx.ld_name).where(
|
|
WalletAddressOkx.ld_name.in_(all_ld_names),
|
|
WalletAddressOkx.project_name == project_name
|
|
)]
|
|
|
|
# 找出未分配的 ld_name
|
|
unassigned_ld_names = [ld_name for ld_name in all_ld_names if ld_name not in assigned_ld_names]
|
|
|
|
# 批量查询未使用的 OKX 钱包地址信息
|
|
unused_okx_infos = list(WalletAddressOkx.select().where(
|
|
WalletAddressOkx.ld_name.is_null(),
|
|
WalletAddressOkx.project_name.is_null(),
|
|
WalletAddressOkx.server_ip.is_null(),
|
|
WalletAddressOkx.stast.is_null()
|
|
))
|
|
|
|
# 准备批量更新的数据
|
|
update_data = []
|
|
for ld_name, okx_info in zip(unassigned_ld_names, unused_okx_infos):
|
|
update_data.append({
|
|
'id': okx_info.id,
|
|
'phone': ld_name,
|
|
'project_name': project_name
|
|
})
|
|
|
|
# 批量更新数据库
|
|
with WalletAddressOkx._meta.database.atomic():
|
|
for data in update_data:
|
|
WalletAddressOkx.update(
|
|
ld_name=data['phone'],
|
|
project_name=data['project_name']
|
|
).where(WalletAddressOkx.id == data['id']).execute()
|
|
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}") |