Compare commits

...

6 Commits

Author SHA1 Message Date
0b07ee8b8f Bump version: 0.25.1.1 → 0.25.1.2 2021-07-20 14:47:17 +03:00
b8884b4877 Requirement update
Bugfix
2021-07-20 14:05:54 +03:00
5a1f7801a2 Bump version: 0.25.1 → 0.25.1.1 2021-07-20 13:16:55 +03:00
17845f750c Bugfix 2021-07-20 13:14:13 +03:00
883af51197 Bump version: 0.25.0.4 → 0.25.1 2021-07-10 01:32:57 +03:00
814cb5ab87 Programmatic user agent spoofing 2021-07-10 01:29:31 +03:00
7 changed files with 45 additions and 41 deletions

View File

@ -4,7 +4,7 @@
__author__ = """Eriks Karls"""
__email__ = 'eriks@72.lv'
__version__ = '0.25.0.4'
__version__ = '0.25.1.2'
from erepublik.citizen import Citizen

View File

@ -15,27 +15,6 @@ __all__ = ['SlowRequests', 'CitizenAPI']
class SlowRequests(Session):
last_time: datetime.datetime
timeout: datetime.timedelta = datetime.timedelta(milliseconds=500)
_uas: List[str] = [
# Chrome
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
# FireFox
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0',
]
debug: bool = False
def __init__(self, proxies: Dict[str, str] = None, user_agent: str = None):
@ -43,7 +22,7 @@ class SlowRequests(Session):
if proxies:
self.proxies = proxies
if user_agent is None:
user_agent = random.choice(self._uas)
user_agent = random.choice(self.get_random_user_agent())
self.request_log_name = utils.get_file(utils.now().strftime("debug/requests_%Y-%m-%d.log"))
self.last_time = utils.now()
self.headers.update({'User-Agent': user_agent})
@ -115,6 +94,36 @@ class SlowRequests(Session):
data = dump.dump_all(response)
utils.write_file(f'debug/dumps/{fd_time}_{fd_name}{fd_extra}.{fd_ext}.dump', data.decode('utf8'))
@staticmethod
def get_random_user_agent() -> str:
windows_x64 = 'Windows NT 10.0; Win64; x64'
linux_x64 = 'X11; Linux x86_64'
android_11 = 'Android 11; Mobile'
android_10 = 'Android 10; Mobile'
android_9 = 'Android 9; Mobile'
firefox_tmplt = 'Mozilla/5.0 ({osystem}; rv:{version}.0) Gecko/20100101 Firefox/{version}.0'
ff_version = range(85, 92)
chrome_tmplt = 'Mozilla/5.0 ({osystem}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{version} Safari/537.36'
chrome_version = ['85.0.4183.121',
'86.0.4240.183',
'87.0.4280.141',
'88.0.4324.182',
'89.0.4389.128',
'90.0.4430.18',
'91.0.4472.73',
'92.0.4515.14']
uas = []
for osystem in [windows_x64, linux_x64, android_9, android_10, android_11]:
for version in ff_version:
uas.append(firefox_tmplt.format(osystem=osystem, version=version))
for version in chrome_version:
uas.append(chrome_tmplt.format(osystem=osystem, version=version))
return random.choice(uas)
class CitizenBaseAPI:
url: str = "https://www.erepublik.com/en"

View File

@ -795,11 +795,7 @@ class BaseCitizen(access_points.CitizenAPI):
if r.url == f"{self.url}/login":
self.report_error("Citizen email and/or password is incorrect!")
else:
re_name_id = re.search(r'<a data-fblog="profile_avatar" href="/en/citizen/profile/(\d+)" '
r'class="user_avatar" title="(.*?)">', r.text)
self.name = re_name_id.group(2)
self.details.citizen_id = re_name_id.group(1)
self.update_citizen_info(r.text)
self.write_log(f"Logged in as: {self.name}")
self.get_csrf_token()
if re.search('<div id="accountSecurity" class="it-hurts-when-ip">', self.r.text):

View File

@ -232,12 +232,12 @@ def json_decode_object_hook(
def json_load(f, **kwargs):
kwargs.update(object_hook=json_decode_object_hook)
# kwargs.update(object_hook=json_decode_object_hook)
return json.load(f, **kwargs)
def json_loads(s: str, **kwargs):
kwargs.update(object_hook=json_decode_object_hook)
# kwargs.update(object_hook=json_decode_object_hook)
return json.loads(s, **kwargs)

View File

@ -8,14 +8,14 @@ isort==5.9.2
pip==21.1.3
pre-commit==2.13.0
pur==5.4.2
PyInstaller==4.3
PyInstaller==4.4
PySocks==1.7.1
pytest==6.2.4
pytz==2021.1
requests==2.25.1
requests==2.26.0
requests-toolbelt==0.9.1
responses==0.13.3
setuptools==57.1.0
Sphinx==4.0.3
setuptools==57.4.0
Sphinx==4.1.1
twine==3.4.1
wheel==0.36.2

View File

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

View File

@ -12,17 +12,16 @@ with open('HISTORY.rst') as history_file:
history = history_file.read()
requirements = [
'PySocks>=1.7.1',
'pytz>=2021.1',
'requests>=2.25.0',
'requests-toolbelt>=0.9.0',
'PySocks==1.7.1',
'pytz==2021.1',
'requests==2.26.0',
'requests-toolbelt==0.9.1',
]
setup_requirements = []
test_requirements = [
"pytest==6.2.4",
"responses==0.13.3"
]
setup(
@ -51,6 +50,6 @@ setup(
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/eeriks/erepublik/',
version='0.25.0.4',
version='0.25.1.2',
zip_safe=False,
)