Skip to content

Commit

Permalink
Refactor proxy parameter to accept list of proxies (proxies)
Browse files Browse the repository at this point in the history
  • Loading branch information
david96182 committed May 6, 2024
1 parent 8810d65 commit 512e964
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ninja = Ninjemail(
browser="firefox",
captcha_keys={"capsolver": "YOUR_API_KEY"},
sms_keys={"service_name": {"user": "USERNAME", "token": "TOKEN"}},
proxy='http://ip:port',
proxies=['http://ip:port', 'http://ip2:port2'],
auto_proxy=True
)
```
Expand All @@ -114,7 +114,7 @@ The `captcha_keys` parameter is a dictionary that contains the **API keys for su

The `sms_keys` parameter is a dictionary that contains the **API key/s for the SMS service/s**, based on `config.toml`. The default value is an empty dictionary. You can provide an API key or keys for the SMS services if required. Currently, **"getsmscode"**, **"smspool"** and **"5sim"** are supported.

The `proxy` parameter specifies the proxy server to be used for the creation of the email accounts. It should be a string in the format "http://ip:port" where "ip" is the IP address of the proxy server and "port" is the port number.
The `proxies` parameter specifies the list of proxy servers to be used for the creation of email accounts. Is optional and can accept either a single proxy server or multiple proxy servers in a list. Each proxy should be provided as a string in the format "http://ip:port," where "ip" represents the IP address of the proxy server and "port" represents the port number.

The `auto_proxy` parameter is a boolean flag that determines whether Ninjemail should automatically obtain and rotate free proxies during automation tasks. If `auto_proxy` is set to `True`, Ninjemail will handle the process of acquiring and managing free proxies internally.

Expand Down
10 changes: 5 additions & 5 deletions ninjemail/ninjemail_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self,
browser="firefox",
captcha_keys={},
sms_keys={},
proxy=None,
proxies=None,
auto_proxy=False
):
"""
Expand All @@ -61,7 +61,7 @@ def __init__(self,
browser (str, optional): The browser to be used for automation. Default is "firefox".
captcha_keys (dict, optional): The API keys for captcha solving services. Default is an empty dictionary.
sms_keys (dict, optional): The API keys for SMS services. Default is an empty dictionary.
proxy (str, optional): The proxy to use for the webdriver. Default is None.
proxies (list, optional): List of proxies to use for the webdriver. Default is None.
auto_proxy (bool, optional): Flag to indicate whether to use free proxies. Default is False.
"""
if browser not in SUPPORTED_BROWSERS:
Expand All @@ -76,7 +76,7 @@ def __init__(self,
self.default_sms_service = DEFAULT_SMS_SERVICE
self.supported_solvers_by_email = SUPPORTED_SOLVERS_BY_EMAIL

self.proxy = proxy
self.proxies = proxies
self.auto_proxy = auto_proxy

#Set up logging
Expand Down Expand Up @@ -104,8 +104,8 @@ def get_proxy(self):
"""
Returns a proxy if user provided one or tries to get a free proxy if auto_proxy is enabled.
"""
if self.proxy:
return self.proxy
if self.proxies:
return random.choice(self.proxies)
elif self.auto_proxy:
try:
logging.info('Getting Free Proxy..')
Expand Down
2 changes: 0 additions & 2 deletions ninjemail/sms_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ def get_sms_instance(sms_info, email_provider):
data.update({'service': email_provider})
sms_provider = fivesim.FiveSim(**data)

print(data)

return sms_provider
8 changes: 4 additions & 4 deletions ninjemail/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_init_invalid_browser():
def test_get_proxy_with_provided_proxy(mocker):
"""Tests get_proxy with a user-provided proxy."""
proxy = "http://myproxy:8080"
manager = Ninjemail(proxy=proxy)
manager = Ninjemail(proxies=[proxy])
assert manager.get_proxy() == proxy
mocker.assert_not_called() # Assert FreeProxy.get wasn't called

Expand Down Expand Up @@ -166,7 +166,7 @@ def test_create_outlook_account_no_info():

def test_create_outlook_account_with_proxy():

manager = Ninjemail(browser='chrome', captcha_keys={'capsolver': {'token': 'aaaaaaaa'}}, proxy='http://127.0.0.1:8080')
manager = Ninjemail(browser='chrome', captcha_keys={'capsolver': {'token': 'aaaaaaaa'}}, proxies=['http://127.0.0.1:8080'])
username, password = manager.create_outlook_account(
)

Expand Down Expand Up @@ -213,7 +213,7 @@ def test_create_gmail_account_no_info():

def test_create_gmail_account_with_proxy():

manager = Ninjemail(sms_keys={'smspool': {'token': 'aaaaaaaa'}}, proxy='http://127.0.0.1:8080')
manager = Ninjemail(sms_keys={'smspool': {'token': 'aaaaaaaa'}}, proxies=['http://127.0.0.1:8080'])
username, password = manager.create_gmail_account(
)

Expand Down Expand Up @@ -262,7 +262,7 @@ def test_create_yahoo_account_no_info():
def test_create_yahoo_account_with_proxy():

manager = Ninjemail(browser='chrome', captcha_keys={'capsolver': {'token': 'aaaaaaaa'}},
sms_keys={'smspool': {'token': 'bbbbbb'}}, proxy='http://127.0.0.1:8080')
sms_keys={'smspool': {'token': 'bbbbbb'}}, proxies=['http://127.0.0.1:8080'])
username, password = manager.create_yahoo_account(
)

Expand Down

0 comments on commit 512e964

Please sign in to comment.