forked from youngesbill/snapchatAPI
-
Notifications
You must be signed in to change notification settings - Fork 2
/
QueryTools2.py
76 lines (66 loc) · 2.03 KB
/
QueryTools2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
from base64 import b64decode, b64encode
import Crypto.Cipher.AES
import json
##################################
# QueryTools to perform requests #
##################################
class QueryTools():
def __init__(self, username, password):
# URL AND KEY FOR API
self.url = 'ASK FOR url AT [email protected]'
self.privateKey = 'ASK FOR KEY AT [email protected]'
self.publicKey = 'ASK FOR KEY AT [email protected]'
# Account Credentials
self.username = username
self.password = password
def pad(self, s):
remainder = (len(s) % 16)
return s + chr(16 - remainder) * (16 - remainder)
def unpad(self, s):
for i in ['\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\n']:
s = s.replace(i, '')
return s
# To encrypt
def encryption(self, s):
padded = self.pad(s)
return b64encode(Crypto.Cipher.AES.new(self.privateKey, Crypto.Cipher.AES.MODE_CBC, "\x00" * 16).encrypt(padded.encode('utf8')))
# To decrypt
def decryption(self, s):
return self.unpad(Crypto.Cipher.AES.new(self.privateKey, Crypto.Cipher.AES.MODE_CBC, "\x00" * 16).decrypt(b64decode(s)))
# Get the tokens with the good endpoint
def get_tokens(self, endpoint = "/loq/login", auth_token = ""):
dataJson = {
"username": self.username,
"password": self.password,
"endpoint": endpoint
}
if len(auth_token):
dataJson['token'] = auth_token
dataEncoded = self.encryption(json.dumps(dataJson))
params = {
'data': dataEncoded,
'publicKey': self.publicKey
}
try:
r = requests.get(self.url + '/endpoint/auth', params = params)
return r.json()
except Exception, e:
print e
return {
'status_code': 500
}
def checkUser(self, rlogin):
data = {
'data': json.dumps(rlogin),
'username': self.username,
'password': self.password
}
try:
r = requests.post(self.url + '/check/check', data = data)
return r.json()
except Exception, e:
print e
return {
'status_code': 500
}