diff --git a/ninjemail/email_providers/gmail.py b/ninjemail/email_providers/gmail.py index dae3741..81c39a2 100644 --- a/ninjemail/email_providers/gmail.py +++ b/ninjemail/email_providers/gmail.py @@ -6,7 +6,7 @@ from selenium.webdriver.support.ui import Select from selenium.webdriver.common.keys import Keys from selenium.webdriver.remote.webelement import WebElement -from sms_services import getsmscode, smspool, fivesim +from sms_services import get_sms_instance URL = 'https://accounts.google.com/signup' WAIT = 5 @@ -56,20 +56,7 @@ def create_account(driver, """ SMS_SERVICE = sms_key['name'] - - if SMS_SERVICE == 'getsmscode': - data = sms_key['data'] - data.update({'project': 1, - 'country': 'hk'}) - sms_provider = getsmscode.GetsmsCode(**data) - elif SMS_SERVICE == 'smspool': - data = sms_key['data'] - data.update({'service': 395}) - sms_provider = smspool.SMSPool(**data) - elif SMS_SERVICE == '5sim': - data = sms_key['data'] - data.update({'service': 'google'}) - sms_provider = fivesim.FiveSim(**data) + sms_provider = get_sms_instance(sms_key) logging.info('Creating Gmail account') diff --git a/ninjemail/email_providers/yahoo.py b/ninjemail/email_providers/yahoo.py index e421e2b..f91487c 100644 --- a/ninjemail/email_providers/yahoo.py +++ b/ninjemail/email_providers/yahoo.py @@ -5,7 +5,7 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import Select from selenium.webdriver.common.keys import Keys -from sms_services import getsmscode, smspool, fivesim +from sms_services import get_sms_instance URL = 'https://login.yahoo.com/account/create' WAIT = 25 @@ -40,20 +40,7 @@ def create_account(driver, """ SMS_SERVICE = sms_key['name'] - - if SMS_SERVICE == 'getsmscode': - data = sms_key['data'] - data.update({'project': 15, - 'country': 'us'}) - sms_provider = getsmscode.GetsmsCode(**data) - elif SMS_SERVICE == 'smspool': - data = sms_key['data'] - data.update({'service': 1034}) - sms_provider = smspool.SMSPool(**data) - elif SMS_SERVICE == '5sim': - data = sms_key['data'] - data.update({'service': 'yahoo'}) - sms_provider = fivesim.FiveSim(**data) + sms_provider = get_sms_instance(sms_key) logging.info('Creating Yahoo account') diff --git a/ninjemail/sms_services/__init__.py b/ninjemail/sms_services/__init__.py index e69de29..a9b1430 100644 --- a/ninjemail/sms_services/__init__.py +++ b/ninjemail/sms_services/__init__.py @@ -0,0 +1,30 @@ +from sms_services import getsmscode +from sms_services import smspool +from sms_services import fivesim + +def get_sms_instance(sms_info): + """ + Retrieves an instance of an SMS provider based on the given SMS information. + + Args: + sms_info (dict): A dictionary containing the SMS service name and associated data. + + Returns: + object: An instance of the SMS provider based on the provided SMS service. + """ + service_name = sms_info['name'] + + if service_name == 'getsmscode': + data = sms_info['data'] + data.update({'project': 1, 'country': 'hk'}) + sms_provider = getsmscode.GetsmsCode(**data) + elif service_name == 'smspool': + data = sms_info['data'] + data.update({'service': 395}) + sms_provider = smspool.SMSPool(**data) + elif service_name == '5sim': + data = sms_info['data'] + data.update({'service': 'google'}) + sms_provider = fivesim.FiveSim(**data) + + return sms_provider