Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import re
- import json
- '''import datetime'''
- path = 'otp_szep.cfg'
- outFile = 'otp_szep_egyenleg.txt'
- url_api = 'https://magan.szepkartya.otpportalok.hu/ajax/egyenleglekerdezes/'
- url_html = 'https://magan.szepkartya.otpportalok.hu/fooldal/'
- def to_int(e):
- return 0 if e.strip() == '' else int(e.strip().replace('+', ''))
- try:
- with open(path) as json_file:
- data = json.load(json_file)
- except FileNotFoundError:
- print(f"ERROR: Nem letezo file: '{path}'")
- print(f" file tartalma ehhez hasonlo legyen:")
- print(' { "azonosito":"12345678", "telekod":"678" }')
- print(' "azonosito" erteke: a kartya utolso 8 szama ')
- print(' "telekod" erteke: a megadott telekod, vagy a kartya utolso 3 szama')
- print(' Az idezojelek fontosak!!!')
- exit(1)
- """GET TOKENS"""
- r = requests.get(url_html)
- match = re.search(r'ajax_token = \'([a-z0-9]{64})\'', r.text)
- token = match.group(1)
- phpsess = r.cookies['PHPSESSID']
- """GET BALLANCE"""
- body = f's_azonosito_k={data["azonosito"]}&s_telekod_k={data["telekod"]}&ajax_token={token}&s_captcha='
- cookies = dict(PHPSESSID=phpsess)
- headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
- resp_api = requests.post(url_api, headers=headers, data=body, cookies=cookies)
- resp_json = json.loads(resp_api.text)
- if resp_json[0] == 'RC':
- print('ERROR: Captcha protection kicked in (too many requests)')
- else:
- vendeglatas = to_int(resp_json[1]['szamla_osszeg7'])
- szabadido = to_int(resp_json[1]['szamla_osszeg8'])
- szallas = to_int(resp_json[1]['szamla_osszeg9'])
- out = '-'*80+'\n'
- '''out += datetime.datetime.now().strftime("%Y.%m.%d %H:%M:%S")'''
- out += f' Azonosito: {data["azonosito"]:9}\n'
- out += f' vendeglatas: {vendeglatas:>9,}\n'
- out += f' szabadido: {szabadido:>9,}\n'
- out += f' szallas: {szallas:>9,}\n'
- out += f' lekerdezes: {resp_json[1]["lekerdezes_idopontja"]}\n'
- print(out)
- print('-'*80)
- f=open(outFile, 'a')
- f.write(out)
- f.close()
Add Comment
Please, Sign In to add comment