Skip to content

Instantly share code, notes, and snippets.

@limitedeternity
Created July 31, 2019 09:42
Show Gist options
  • Save limitedeternity/4337e635b6a741bb7881e3b9b065be3a to your computer and use it in GitHub Desktop.
Save limitedeternity/4337e635b6a741bb7881e3b9b065be3a to your computer and use it in GitHub Desktop.
Megafon balance and personal offer checker
from pathlib import Path
import pickle
from requests import Session
import sys
s = Session()
s.headers.update({"User-Agent": "MLK Android Phone 3.3.4"})
cookiejar = Path("cookiejar")
if cookiejar.exists():
with cookiejar.open("rb") as j:
s.cookies.update(pickle.load(j))
phone = input("Введите свой номер телефона без +7: ")
pin = input("Введите пин: ")
auth_res = s.post("https://api.megafon.ru/mlk/auth/pin", json={"captcha": None, "msisdn": phone, "pin": pin})
if auth_res.json()["status"]["id"] != 1:
print("Ошибка. Аккаунт неактивен")
exit(1)
else:
phone = input("Введите свой номер телефона без +7: ")
otp_res = s.post("https://api.megafon.ru/mlk/auth/otp/request", data={"login": phone})
if not otp_res.json()["ok"]:
print("Ошибка. Код не отправлен")
exit(1)
otp = input("Код был отправлен на ваш телефон. Введите его: ")
auth_res = s.post("https://api.megafon.ru/mlk/auth/otp/submit", data={"login": phone, "otp": otp})
if auth_res.json()["status"]["id"] != 1:
print("Ошибка. Аккаунт неактивен")
exit(1)
pin = input("Осталось придумать четырехзначный пин-код для входа. Введите его: ")
s.post("https://api.megafon.ru/mlk/api/profile/pin", json={"captcha": None, "pin": pin})
with cookiejar.open("wb") as j:
pickle.dump(s.cookies, j)
if len(sys.argv) > 1 and sys.argv[1] == "logout":
s.post("https://api.megafon.ru/mlk/logout")
cookiejar.unlink()
exit(0)
balance_res = s.get("https://api.megafon.ru/mlk/api/main/balance")
personal_offer_res = s.get("https://api.megafon.ru/mlk/api/personaloffer/summary")
print(f"\nБаланс: {balance_res.json()['balance']}.\nПерсональные предложения: {'есть' if personal_offer_res.json()['is_offer_available'] else 'нет'}.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment