+ Raise error if cannot login

This commit is contained in:
Wong Yiek Heng 2025-10-04 11:19:51 +08:00
parent 27d56b8275
commit e5ccafe4b5
2 changed files with 19 additions and 12 deletions

View File

@ -432,8 +432,8 @@ class CM_BOT:
data=transfer_data,
headers=self.transfer_credit_headers
)
# with open('transfer_credit.html', 'wb') as f:
# f.write(response.content)
with open('transfer_credit.html', 'wb') as f:
f.write(response.content)
return True if re.search(r'Successfully saved the record\.', response.text) else False
def get_user_credit(self):

View File

@ -66,10 +66,11 @@ class CM_BOT_HAL:
cm_bot = CM_BOT()
username = self.get_next_username(self.prefix)
password = self.get_random_password()
cm_bot.login(
if cm_bot.login(
username = self.agent_id,
password = self.agent_password
)
) == False:
raise Exception(f'[Cannot login] {self.agent_id} cannot login.')
cm_bot.register_user(
user_id = username,
user_password = password
@ -77,10 +78,11 @@ class CM_BOT_HAL:
cm_bot.logout()
cm_bot = CM_BOT()
cm_bot.login(
if cm_bot.login(
username = username,
password = password
)
) == False:
raise Exception(f'[Cannot login] {username} cannot login.')
link = cm_bot.get_register_link()
cm_bot.logout()
@ -133,10 +135,11 @@ class CM_BOT_HAL:
t_username, f_username = self.get_whatsapp_link_username(whatsapp_link)
password = self.get_user_pass_from_acc(f_username)
cm_bot = CM_BOT()
cm_bot.login(
if cm_bot.login(
username = f_username,
password = password
)
) == False:
raise Exception(f'[Cannot login] {f_username} cannot login.')
if cm_bot.set_security_pin(self.security_pin) == False:
cm_bot.logout()
raise Exception(f'Agent acc: {f_username} already has security pin!')
@ -159,19 +162,23 @@ class CM_BOT_HAL:
def get_user_credit(self, f_username: str, f_password: str):
cm_bot = CM_BOT()
cm_bot.login(
if cm_bot.login(
username = f_username,
password = f_password
)
) == False:
raise Exception(f'[Cannot login] {f_username} cannot login.')
return float(cm_bot.get_user_credit())
def transfer_credit_api(self, f_username: str, f_password: str, t_username: str, t_password: str):
cm_bot = CM_BOT()
cm_bot.login(
if cm_bot.login(
username = f_username,
password = f_password
)
) == False:
raise Exception(f'[Cannot login] {f_username} cannot login.')
amount = cm_bot.get_user_credit() - 0.01
if amount <= 0.01:
print(f'[No enough credit] {t_username} do not have enough credit.')
if cm_bot.transfer_credit(t_username, t_password, amount) == True:
print(f'Successfully transfer amount: {amount} from {f_username} to {t_username}')
else: