Added proxy support 😉
This commit is contained in:
parent
2e26c2db79
commit
3b1c1928fd
@ -38,8 +38,10 @@ class SlowRequests(Session):
|
|||||||
]
|
]
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, proxies: Dict[str, str] = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
if proxies:
|
||||||
|
self.proxies = proxies
|
||||||
self.request_log_name = utils.get_file(utils.now().strftime("debug/requests_%Y-%m-%d.log"))
|
self.request_log_name = utils.get_file(utils.now().strftime("debug/requests_%Y-%m-%d.log"))
|
||||||
self.last_time = utils.now()
|
self.last_time = utils.now()
|
||||||
self.headers.update({
|
self.headers.update({
|
||||||
@ -132,6 +134,14 @@ class CitizenBaseAPI:
|
|||||||
def _get_main(self) -> Response:
|
def _get_main(self) -> Response:
|
||||||
return self.get(self.url)
|
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):
|
class ErepublikAnniversaryAPI(CitizenBaseAPI):
|
||||||
def _post_main_collect_anniversary_reward(self) -> Response:
|
def _post_main_collect_anniversary_reward(self) -> Response:
|
||||||
|
@ -7,11 +7,11 @@ isort==5.5.3
|
|||||||
pip==20.2.3
|
pip==20.2.3
|
||||||
PyInstaller==4.0
|
PyInstaller==4.0
|
||||||
pytz==2020.1
|
pytz==2020.1
|
||||||
pytest==6.0.2
|
pytest==6.1.0
|
||||||
responses==0.12.0
|
responses==0.12.0
|
||||||
setuptools==50.3.0
|
setuptools==50.3.0
|
||||||
Sphinx==3.2.1
|
Sphinx==3.2.1
|
||||||
requests==2.24.0
|
requests[socks]==2.24.0
|
||||||
tox==3.20.0
|
tox==3.20.0
|
||||||
twine==3.2.0
|
twine==3.2.0
|
||||||
watchdog==0.10.3
|
watchdog==0.10.3
|
||||||
|
2
setup.py
2
setup.py
@ -11,7 +11,7 @@ with open('README.rst') as readme_file:
|
|||||||
with open('HISTORY.rst') as history_file:
|
with open('HISTORY.rst') as history_file:
|
||||||
history = history_file.read()
|
history = history_file.read()
|
||||||
|
|
||||||
requirements = ['pytz==2020.1', 'requests==2.24.0']
|
requirements = ['pytz==2020.1', 'requests[socks]==2.24.0']
|
||||||
|
|
||||||
setup_requirements = []
|
setup_requirements = []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user