diff --git a/cm_bot.py b/cm_bot.py index 70130e5..27cf98d 100644 --- a/cm_bot.py +++ b/cm_bot.py @@ -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): diff --git a/cm_bot_hal.py b/cm_bot_hal.py index b0493ac..64624fb 100644 --- a/cm_bot_hal.py +++ b/cm_bot_hal.py @@ -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: