Skip to content

Commit

Permalink
megafon fix old lk
Browse files Browse the repository at this point in the history
  • Loading branch information
artyl committed Sep 30, 2022
1 parent 4ae9cb7 commit a86fbd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions changelist.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,6 @@ FIX: МТС после пароля появилось окно с предло

## mbplugin v1.00.34 (21.09.22) mts email skip, life.com.by
FIX: Исправления провайдера a1.by (сотовая связь Беларусь) от Exemok

## mbplugin v1.00.35 (30.09.22) fix megafon
FIX: Исправлена работа Мегафон (ссылка личного кабинета переехала https://old.lk.megafon.ru/) Пока временное быстрое решение.
28 changes: 14 additions & 14 deletions plugin/megafon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
interUnit = 'GB'
icon = '789C73F235636100033320D600620128666450804840E591C1FFFFFFB1E237DF1F32CCBF91C7B0F66E13C3D3AFD771AA43C63FFE7C6688D8C5CC10B69381E1FCEB6D601A19171ED1C0A9F7CCAB4D286AB1E987E15B1F8EA1E9FF87A1069F7E10FEF7FF2F5C7FDC5E1E9CFA41F265C7F4C1EA57DDA963C838280516CB3C2803D78FCD7C64FDFD1743C1F4D9D79B196A4E5AC0F5806850D8E2D38F0F5F7EBB8761F59D7AAC725B1FF4E1751F084FBF92C8B0FDD124BC76E0D33FE95214C3B73F1F71EA8BDDC385573FC88FB8E441E2317B38F0EA87F96FF2A56892DD0F731BA130C225F7EFFF1F14FDBFFE7E235AFFA5B7BB71E683C5378B71EA8FD9C389926E09E10B6F7680E9EBEF0FE1540300F7C7D83E'

login_url = 'https://lk.megafon.ru/'
login_url = 'https://old.lk.megafon.ru/'
login_checkers = ['<input[^>]*name="CSRF"[^>]*', '<input[^>]*name="j_username"[^>]*', '<input[^>]*name="j_password"[^>]*', '<input[^>]*type="submit"[^>]*']


Expand All @@ -25,7 +25,7 @@ def get_state():
username, password, submit, submit_txt, lk_inside = res
return States(username, password, submit, submit_txt, lk_inside)

self.baseurl = 'https://lk.megafon.ru/'
self.baseurl = 'https://old.lk.megafon.ru/'
States = collections.namedtuple('States', 'username, password, submit, submit_txt, lk_inside')
self.page_goto(self.baseurl)
self.sleep(1)
Expand Down Expand Up @@ -89,10 +89,10 @@ def get_state():
self.page_goto(self.baseurl + '/../../options')
self.sleep(3)
self.page_screenshot()
self.page_goto('https://beta.lk.megafon.ru')
self.page_goto('https://beta.old.lk.megafon.ru')
self.sleep(3)
self.page_screenshot()
self.page_goto('https://beta.lk.megafon.ru/options')
self.page_goto('https://beta.old.lk.megafon.ru/options')
self.sleep(3)
self.page_screenshot()
#breakpoint()
Expand All @@ -118,21 +118,21 @@ def get_balance_browser(login, password, storename=None, **kwargs):
def get_balance_api(login, password, storename=None, **kwargs):
result = {}
session = store.Session(storename)
response3 = session.get('https://lk.megafon.ru/api/lk/main/atourexpense')
response3 = session.get('https://old.lk.megafon.ru/api/lk/main/atourexpense')
if 'json' in response3.headers.get('content-type') and 'balance' in response3.text:
logging.info('Old session is ok')
else: # Нет, логинимся
logging.info('Old session is bad, relogin')
session.drop_and_create()
response1 = session.get('https://lk.megafon.ru/login/')
response1 = session.get('https://old.lk.megafon.ru/login/')
if response1.status_code != 200:
raise RuntimeError(f'GET Login page error: status_code {response1.status_code}!=200')
csrf = re.search('(?usi)name="CSRF" value="([^\"]+)"', response1.text)
data = {'CSRF': csrf, 'j_username': f'+7{login}', 'j_password': password}
response2 = session.post('https://lk.megafon.ru/dologin/', data=data)
response2 = session.post('https://old.lk.megafon.ru/dologin/', data=data)
if response2.status_code != 200:
raise RuntimeError(f'POST Login page error: status_code {response2.status_code}!=200')
response3 = session.get('https://lk.megafon.ru/api/lk/main/atourexpense')
response3 = session.get('https://old.lk.megafon.ru/api/lk/main/atourexpense')
if response3.status_code != 200 or 'json' not in response3.headers.get('content-type'):
raise RuntimeError(f'Get Balance page not return json: status_code={response2.status_code} {response3.headers.get("content-type")}')
if 'balance' not in response3.text:
Expand All @@ -142,12 +142,12 @@ def get_balance_api(login, password, storename=None, **kwargs):
result['KreditLimit'] = response3.json().get('limit', 0)

try:
response4 = session.get('https://lk.megafon.ru/api/profile/name')
response4 = session.get('https://old.lk.megafon.ru/api/profile/name')
if response4.status_code == 200 and 'json' in response4.headers.get('content-type'):
result['UserName'] = response4.json()['name'].replace('"','').replace("'",'').replace('&quot;','')

response5_new = session.get('https://lk.megafon.ru/api/tariff/2019-3/current')
response5 = session.get('https://lk.megafon.ru/api/tariff/current')
response5_new = session.get('https://old.lk.megafon.ru/api/tariff/2019-3/current')
response5 = session.get('https://old.lk.megafon.ru/api/tariff/current')
if response5.status_code != 200:
response5 = response5_new
if response5.status_code == 200 and 'json' in response5.headers.get('content-type'):
Expand All @@ -158,12 +158,12 @@ def get_balance_api(login, password, storename=None, **kwargs):


#Старый вариант без получения стоимости платных услуг
#response6 = session.get('https://lk.megafon.ru/api/lk/mini/options')
#response6 = session.get('https://old.lk.megafon.ru/api/lk/mini/options')
#if response6.status_code == 200 and 'json' in response6.headers.get('content-type'):
# servicesDto = response6.json().get('servicesDto', {})
# result['UslugiOn'] = f"{servicesDto.get('free','')}/{servicesDto.get('paid','')}"
try:
response6 = session.get('https://lk.megafon.ru/api/options/list/current')
response6 = session.get('https://old.lk.megafon.ru/api/options/list/current')
if response6.status_code == 200 and 'json' in response6.headers.get('content-type'):
oList = response6.json()
services = [(i['optionName'], i['monthRate'] * (1 if i['monthly'] else 30)) for i in oList.get('paid', [])]
Expand All @@ -179,7 +179,7 @@ def get_balance_api(login, password, storename=None, **kwargs):
logging.error(exception_text)

try:
response7 = session.get('https://lk.megafon.ru/api/options/remaindersMini')
response7 = session.get('https://old.lk.megafon.ru/api/options/remaindersMini')
if response7.status_code == 200 and 'json' in response7.headers.get('content-type'):
r7_remainders = response7.json().get('remainders', []) # {.., remainders: [{remainders:[{...},{...}], ...]...}, ...}
remainders = sum([i.get('remainders', []) for i in r7_remainders if 'в крыму' not in i.get('name', '').lower()], [])
Expand Down

0 comments on commit a86fbd4

Please sign in to comment.