Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import sys
- import os
- from xml.etree import ElementTree as etree
- def login(username, password, force=False):
- folder = "./.data/"
- if not os.path.exists(folder):
- os.makedirs(folder)
- info_file = folder+username.lower()+".json"
- try:
- with open(info_file,"r") as f: f.close() #Create file if not exists
- except:
- with open(info_file,"w") as f: f.close() #Create file if not exists
- with open(info_file,"r+") as f:
- data = f.read()
- f.seek(0)
- if data == "":
- data = "{}"
- data = json.loads(data)
- device_id = data["d"] if "d" in data else ""
- if type(data) != dict:
- if not force:
- return data[1]
- device_id = data[0]
- headers = {
- 'Pragma': 'no-cache',
- 'Origin': 'https://xat.com',
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.8',
- 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
- 'Content-type': 'application/x-www-form-urlencoded',
- 'Accept': '*/*',
- 'Cache-Control': 'no-cache',
- 'Referer': 'https://xat.com/login',
- 'Connection': 'keep-alive',
- }
- params = (
- ('v', '1.9.2'),
- ('m', '7'),
- ('sb', '1'),
- ('', ''),
- )
- data = [
- ('json', '{"M": "0", "P": "", "d": "'+device_id+'", "n": "'+username+'", "nfy": "", "oi": "0", "p": "'+password+'", "pt": "3", "t": ""}'),
- ]
- res = requests.post('http://mt.xat.com/web_gear/chat/mlogin2.php?v=1.9.2&m=7&sb=1&', headers=headers, data=data)
- data = json.loads(res.text)
- if type(data) == int:
- print("Error... #"+str(data))
- if data == 1:
- print("Login blocked. Wait a while before trying again lol.")
- print("I actually have no clue what any of the rest mean, good luck.")
- sys.exit(0)
- if "d" in data:
- f.write(json.dumps(data))
- print(data["s"])
- f.truncate()
- sys.exit()
- elif "v" in data:
- data = etree.XML(data["v"])
- if "e" in data.attrib:
- print("Incorrect password.")
- sys.exit()
- f.write(json.dumps([device_id, data.attrib]))
- data = data.attrib
- f.truncate()
- return data
- login_data = login("username", "password")
- print(login_data)
- """
- Should return something like
- {
- "d0":"123456789",
- "d3":"1234567",
- "dt":"123456789",
- "i":"123456789",
- "n":"Username",
- "k2":"123456789",
- "k3":"123456789",
- "k1":"6896uteriojtfhsdkl"
- }
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement