Compare commits

...

2 Commits

Author SHA1 Message Date
7f3bd9b864 Bump version: 0.24.0.2 → 0.24.0.3 2021-01-28 01:46:11 +02:00
9154d2e493 Captcha solving 2021-01-28 01:46:03 +02:00
5 changed files with 25 additions and 23 deletions

View File

@ -4,7 +4,7 @@
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.24.0.2'
__version__ = '0.24.0.3'
from erepublik import classes, constants, utils
from erepublik.citizen import Citizen

View File

@ -141,6 +141,25 @@ class CitizenBaseAPI:
url = f'http://{username}:{password}@{host}:{port}' if username and password else f'socks5://{host}:{port}'
self._req.proxies = dict(http=url)
def _get_main_session_captcha(self) -> Response:
return self.get(f'{self.url}/main/sessionCaptcha')
def _get_main_session_unlock_popup(self) -> Response:
return self.get(f'{self.url}/main/sessionUnlockPopup')
def _post_main_session_get_challenge(self, captcha_id: int) -> Response:
env = dict(l=['tets', ], s=[], c=["l_chathwe", "l_chatroom"], m=0)
data = dict(_token=self.token, captchaId=captcha_id, env=utils.b64json(env))
return self.post(f'{self.url}/main/sessionGetChallenge', data=data)
def _post_main_session_unlock(
self, captcha: int, image: str, challenge: str, coords: List[Dict[str, int]], src: str
) -> Response:
env = dict(l=['tets', ], s=[], c=["l_chathwe", "l_chatroom"], m=0)
data = dict(_token=self.token, captchaId=captcha, imageId=image, challengeId=challenge,
clickMatrix=coords, isMobile=0, env=utils.b64json(env), src=src)
return self.post(f'{self.url}/main/sessionUnlock', data=data)
class ErepublikAnniversaryAPI(CitizenBaseAPI):
def _post_main_collect_anniversary_reward(self) -> Response:
@ -470,24 +489,6 @@ class ErepublikMilitaryAPI(CitizenBaseAPI):
weaponQuality=weapon, totalEnergy=energy, **kwargs)
return self.post(f"{self.url}/military/fightDeploy-startDeploy", data=data)
def _get_main_session_captcha(self) -> Response:
return self.get(f'{self.url}/main/sessionCaptcha')
def _get_main_session_unlock_popup(self) -> Response:
return self.get(f'{self.url}/main/sessionUnlockPopup')
def _post_main_session_get_challenge(self, captcha_id: int) -> Response:
env = dict(l=['tets', ], s=[], c=["l_chathwe", "l_chatroom"], m=0)
data = dict(_token=self.token, captchaId=captcha_id, env=utils.b64json(env))
return self.post(f'{self.url}/main/sessionGetChallenge', data=data)
def _post_main_session_unlock(
self, captcha: int, image: str, challenge: str, coords: List[Dict[str, int]], src: str
) -> Response:
env = dict(l=['tets', ], s=[], c=["l_chathwe", "l_chatroom"], m=0)
data = dict(_token=self.token, captchaId=captcha, imageId=image, challengeId=challenge,
clickMatrix=utils.json.dumps(coords), isMobile=0, env=utils.b64json(env), src=src)
return self.post(f'{self.url}/main/sessionUnlock', data=data)
class ErepublikPoliticsAPI(CitizenBaseAPI):

View File

@ -242,7 +242,7 @@ class BaseCitizen(access_points.CitizenAPI):
"""
self._update_inventory_data(self._get_economy_inventory_items().json())
def do_captcha_challenge(self) -> bool:
def do_captcha_challenge(self, retry: int = 0) -> bool:
r = self._get_main_session_captcha()
data = re.search(r'\$j\.extend\(SERVER_DATA,([^)]+)\)', r.text)
if data:
@ -257,7 +257,8 @@ class BaseCitizen(access_points.CitizenAPI):
return True
else:
self.report_error('Captcha failed!')
return self.do_captcha_challenge()
if retry < 6:
return self.do_captcha_challenge(retry+1)
return False
def solve_captcha(self, src: str) -> List[Dict[str, int]]:

View File

@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.24.0.2
current_version = 0.24.0.3
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.?(?P<dev>\d+)?

View File

@ -50,6 +50,6 @@ setup(
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/eeriks/erepublik/',
version='0.24.0.2',
version='0.24.0.3',
zip_safe=False,
)