Added proxy support 😉

This commit is contained in:
Eriks K 2020-09-29 10:52:14 +03:00
parent 2e26c2db79
commit 3b1c1928fd
3 changed files with 14 additions and 4 deletions

View File

@ -38,8 +38,10 @@ class SlowRequests(Session):
]
debug: bool = False
def __init__(self):
def __init__(self, proxies: Dict[str, str] = None):
super().__init__()
if proxies:
self.proxies = proxies
self.request_log_name = utils.get_file(utils.now().strftime("debug/requests_%Y-%m-%d.log"))
self.last_time = utils.now()
self.headers.update({
@ -132,6 +134,14 @@ class CitizenBaseAPI:
def _get_main(self) -> Response:
return self.get(self.url)
def set_socks_proxy(self, host: str, port: int, username: str = None, password: str = None):
url = f'socks5://{username}:{password}@{host}:{port}' if username and password else f'socks5://{host}:{port}'
self._req.proxies = dict(http=url, https=url)
def set_http_proxy(self, host: str, port: int, username: str = None, password: str = None):
url = f'http://{username}:{password}@{host}:{port}' if username and password else f'socks5://{host}:{port}'
self._req.proxies = dict(http=url)
class ErepublikAnniversaryAPI(CitizenBaseAPI):
def _post_main_collect_anniversary_reward(self) -> Response:

View File

@ -7,11 +7,11 @@ isort==5.5.3
pip==20.2.3
PyInstaller==4.0
pytz==2020.1
pytest==6.0.2
pytest==6.1.0
responses==0.12.0
setuptools==50.3.0
Sphinx==3.2.1
requests==2.24.0
requests[socks]==2.24.0
tox==3.20.0
twine==3.2.0
watchdog==0.10.3

View File

@ -11,7 +11,7 @@ with open('README.rst') as readme_file:
with open('HISTORY.rst') as history_file:
history = history_file.read()
requirements = ['pytz==2020.1', 'requests==2.24.0']
requirements = ['pytz==2020.1', 'requests[socks]==2.24.0']
setup_requirements = []