Advertisement
Venusaur

[Python 3.6+] Xat mobile login

Jun 9th, 2018
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. import json
  2. import sys
  3. import xml.etree.ElementTree as ET
  4. import requests
  5. from pathlib import Path
  6.  
  7.  
  8. def login(username, password, force=False):
  9.     p = Path(f'.data/')
  10.     p.mkdir(parents=True, exist_ok=True)
  11.     p = Path(f'.data/{username.lower()}.json')
  12.     p.touch()
  13.  
  14.     with p.open() as f:
  15.         data = f.read()
  16.  
  17.     if not data:
  18.         data = '{}'
  19.  
  20.     data = json.loads(data)
  21.  
  22.     if not isinstance(data, dict):
  23.         if not force:
  24.             return data[1]
  25.         device_id = data[0]
  26.     else:
  27.         device_id = data.get('d', '')
  28.  
  29.     headers = {
  30.         'Pragma': 'no-cache',
  31.         'Origin': 'https://xat.com',
  32.         'Accept-Encoding': 'gzip, deflate, br',
  33.         'Accept-Language': 'en-US,en;q=0.8',
  34.         'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
  35.         'Content-type': 'application/x-www-form-urlencoded',
  36.         'Accept': '*/*',
  37.         'Cache-Control': 'no-cache',
  38.         'Referer': 'https://xat.com/login',
  39.         'Connection': 'keep-alive',
  40.     }
  41.  
  42.     params = {
  43.         'v': '1.12.0',
  44.         'm': '7',
  45.         'sb': '1',
  46.         '': ''
  47.     }
  48.  
  49.     payload = {
  50.         'json': json.dumps({
  51.             'M': '0',
  52.             'P': '',
  53.             'd': device_id,
  54.             'n': username,
  55.             'nfy': '',
  56.             'oi': '0',
  57.             'p': password,
  58.             'pt': '3',
  59.             't': ''
  60.         })
  61.     }
  62.  
  63.     response = requests.post('https://mt.xat.com/web_gear/chat/mlogin2.php?',
  64.                              params=params, headers=headers, data=payload)
  65.  
  66.     data = response.json()
  67.  
  68.     if isinstance(data, int):
  69.         print(f'Error #{data}')
  70.         if data == 1:
  71.             print('Login blocked. Wait a while before trying again.')
  72.         print('I actually have no clue what any of the rest mean, good luck.')
  73.         sys.exit()
  74.  
  75.     if 'd' in data:
  76.         print(data['s'])
  77.         with p.open('w') as f:
  78.             json.dump(data, f)
  79.         sys.exit()
  80.  
  81.     elif 'v' in data:
  82.         data = ET.XML(data['v'])
  83.         if 'e' in data.attrib:
  84.             print('Incorrect password.')
  85.             sys.exit()
  86.         with p.open('w') as f:
  87.             json.dump([device_id, data.attrib], f)
  88.  
  89.         data = data.attrib
  90.  
  91.     return data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement