Advertisement
austinh115

[PYTHON 2.7, and 3 maybe] xat mobile login

Jun 7th, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. import requests
  2. import json
  3. import sys
  4. import os
  5. from xml.etree import ElementTree as etree
  6.  
  7. def login(username, password, force=False):
  8.     folder = "./.data/"
  9.     if not os.path.exists(folder):
  10.         os.makedirs(folder)
  11.     info_file = folder+username.lower()+".json"
  12.     try:
  13.         with open(info_file,"r") as f: f.close() #Create file if not exists
  14.     except:
  15.         with open(info_file,"w") as f: f.close() #Create file if not exists
  16.     with open(info_file,"r+") as f:
  17.         data = f.read()
  18.         f.seek(0)
  19.  
  20.         if data == "":
  21.             data = "{}"
  22.         data = json.loads(data)
  23.  
  24.         device_id = data["d"] if "d" in data else ""
  25.  
  26.         if type(data) != dict:
  27.             if not force:
  28.                 return data[1]
  29.             device_id = data[0]
  30.  
  31.         headers = {
  32.             'Pragma': 'no-cache',
  33.             'Origin': 'https://xat.com',
  34.             'Accept-Encoding': 'gzip, deflate, br',
  35.             'Accept-Language': 'en-US,en;q=0.8',
  36.             'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
  37.             'Content-type': 'application/x-www-form-urlencoded',
  38.             'Accept': '*/*',
  39.             'Cache-Control': 'no-cache',
  40.             'Referer': 'https://xat.com/login',
  41.             'Connection': 'keep-alive',
  42.         }
  43.  
  44.         params = (
  45.             ('v', '1.9.2'),
  46.             ('m', '7'),
  47.             ('sb', '1'),
  48.             ('', ''),
  49.         )
  50.  
  51.         data = [
  52.             ('json', '{"M": "0", "P": "", "d": "'+device_id+'", "n": "'+username+'", "nfy": "", "oi": "0", "p": "'+password+'", "pt": "3", "t": ""}'),
  53.         ]
  54.  
  55.         res = requests.post('http://mt.xat.com/web_gear/chat/mlogin2.php?v=1.9.2&m=7&sb=1&', headers=headers, data=data)
  56.  
  57.         data = json.loads(res.text)
  58.  
  59.         if type(data) == int:
  60.             print("Error... #"+str(data))
  61.             if data == 1:
  62.                 print("Login blocked. Wait a while before trying again lol.")
  63.             print("I actually have no clue what any of the rest mean, good luck.")
  64.             sys.exit(0)
  65.        
  66.         if "d" in data:
  67.             f.write(json.dumps(data))
  68.             print(data["s"])
  69.             f.truncate()
  70.             sys.exit()
  71.         elif "v" in data:
  72.             data = etree.XML(data["v"])
  73.             if "e" in data.attrib:
  74.                 print("Incorrect password.")
  75.                 sys.exit()
  76.             f.write(json.dumps([device_id, data.attrib]))
  77.             data = data.attrib
  78.  
  79.         f.truncate()
  80.  
  81.         return data
  82.  
  83. login_data = login("username", "password")
  84.  
  85. print(login_data)
  86.  
  87. """
  88. Should return something like
  89. {
  90.     "d0":"123456789",
  91.     "d3":"1234567",
  92.     "dt":"123456789",
  93.     "i":"123456789",
  94.     "n":"Username",
  95.     "k2":"123456789",
  96.     "k3":"123456789",
  97.     "k1":"6896uteriojtfhsdkl"
  98. }
  99. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement