bnghtz

otp_szep.py

Oct 11th, 2020 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. import requests
  2. import re
  3. import json
  4. '''import datetime'''
  5.  
  6. path = 'otp_szep.cfg'
  7. outFile = 'otp_szep_egyenleg.txt'
  8. url_api = 'https://magan.szepkartya.otpportalok.hu/ajax/egyenleglekerdezes/'
  9. url_html = 'https://magan.szepkartya.otpportalok.hu/fooldal/'
  10.  
  11. def to_int(e):
  12.     return 0 if e.strip() == '' else int(e.strip().replace('+', ''))
  13.  
  14. try:
  15.     with open(path) as json_file:
  16.         data = json.load(json_file)
  17. except FileNotFoundError:
  18.     print(f"ERROR: Nem letezo file: '{path}'")
  19.     print(f"  file tartalma ehhez hasonlo legyen:")
  20.     print('  { "azonosito":"12345678", "telekod":"678" }')
  21.     print('      "azonosito" erteke: a kartya utolso 8 szama ')
  22.     print('      "telekod" erteke: a megadott telekod, vagy a kartya utolso 3 szama')
  23.     print('      Az idezojelek fontosak!!!')
  24.     exit(1)
  25.  
  26. """GET TOKENS"""
  27. r = requests.get(url_html)
  28. match = re.search(r'ajax_token = \'([a-z0-9]{64})\'', r.text)
  29. token = match.group(1)
  30. phpsess =  r.cookies['PHPSESSID']
  31.  
  32. """GET BALLANCE"""
  33. body = f's_azonosito_k={data["azonosito"]}&s_telekod_k={data["telekod"]}&ajax_token={token}&s_captcha='
  34. cookies = dict(PHPSESSID=phpsess)
  35. headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
  36. resp_api = requests.post(url_api, headers=headers, data=body, cookies=cookies)
  37. resp_json = json.loads(resp_api.text)
  38. if resp_json[0] == 'RC':
  39.     print('ERROR: Captcha protection kicked in (too many requests)')
  40. else:
  41.     vendeglatas = to_int(resp_json[1]['szamla_osszeg7'])
  42.     szabadido = to_int(resp_json[1]['szamla_osszeg8'])
  43.     szallas = to_int(resp_json[1]['szamla_osszeg9'])
  44.     out = '-'*80+'\n'
  45.     '''out += datetime.datetime.now().strftime("%Y.%m.%d %H:%M:%S")'''
  46.     out += f'  Azonosito:   {data["azonosito"]:9}\n'
  47.     out += f'  vendeglatas: {vendeglatas:>9,}\n'
  48.     out += f'  szabadido:   {szabadido:>9,}\n'
  49.     out += f'  szallas:     {szallas:>9,}\n'
  50.     out += f'  lekerdezes: {resp_json[1]["lekerdezes_idopontja"]}\n'
  51.  
  52.     print(out)
  53.     print('-'*80)
  54.     f=open(outFile, 'a')
  55.     f.write(out)
  56.     f.close()
  57.  
Add Comment
Please, Sign In to add comment