33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from models.tg_models import TelegramAccount
|
|
from models.tg_phone_devices import TgPhoneDevices
|
|
|
|
if __name__ == '__main__':
|
|
# 一次性查询所有满足条件的 TelegramAccount 记录
|
|
telegram_accounts = TelegramAccount.select().where(
|
|
TelegramAccount.is_logged_in_telegram == 1
|
|
)
|
|
|
|
# 一次性查询所有 TgPhoneDevices 记录,并将 phone 作为键存储在字典中
|
|
tg_phone_devices_dict = {
|
|
device.phone:
|
|
device
|
|
for device in TgPhoneDevices.select()
|
|
}
|
|
|
|
n = 0
|
|
n1 = 0
|
|
for tg_info in telegram_accounts:
|
|
# 在字典中查找对应的 TgPhoneDevices 记录
|
|
tg_phone_info = tg_phone_devices_dict.get(tg_info.ld_name)
|
|
if not tg_phone_info or not tg_phone_info.is_valid_session:
|
|
n += 1
|
|
print(tg_info.ld_name, tg_info.server_id)
|
|
|
|
# if tg_phone_info:
|
|
# if tg_phone_info.is_valid_session == 0 or tg_phone_info.is_valid_session is None:
|
|
# n1 += 1
|
|
# print(tg_phone_info.phone, tg_info.server_id)
|
|
|
|
print(n)
|
|
# print(n1)
|