Details

Scripting



Name
NovusBanlist.py
LastWriteTime
2020/09/09 11:06
Description
Python module to use banlist API
Langage
python
ScriptCode
import requests class LoginError(Exception): """Login Error""" pass class Novus: def __init__(self,username, password): self.access_token = "" self.auth(username,password); def auth(self,username, password): global access_token auth = { 'grant_type': 'password', 'username': username, 'password': password } r = requests.post("https://novus.systems/Token", headers={"Content-Type":"application/x-www-form-urlencoded"}, data=auth) bearer = r.json() try: self.access_token = bearer['access_token'] except: raise LoginError(bearer['error_description']) def searchuser(self,UserId): auth = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + self.access_token, 'Content-Type': 'application/json' } rq = requests.get("https://novus.systems/api/BanlistsAPI/"+str(UserId), headers=auth) answer = rq.json() return answer def listuser(self): auth = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + self.access_token, 'Content-Type': 'application/json' } rq = requests.get("https://novus.systems/api/FullBanlistAPI/", headers=auth) answer = rq.json() return answer def adduser(self,UserId, TypeId, Comment, Moderator): auth = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + self.access_token, 'Content-Type': 'application/json' } data = { 'RoboxID': UserId, 'BanlistTypeID': TypeId, 'Comment': Comment, 'Moderator': Moderator } rq = requests.post("https://novus.systems/api/BanlistsAPI/",json=data, headers=auth) answer = rq.json() return answer def updateuser(self,CaseID, Active,TypeId,Comment, Moderator): auth = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + self.access_token, 'Content-Type': 'application/json' } data = { 'BanlistID' : CaseID, 'Active': Active, 'BanlistTypeID': TypeId, 'Comment': Comment, 'Moderator': Moderator } rq = requests.put("https://novus.systems/api/BanlistsAPI/",json=data, headers=auth) answer = rq.json() return answer def deleteuser(self,CaseID): auth = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + self.access_token, 'Content-Type': 'application/json' } data = { 'BanlistID' : CaseID, 'Delete': True } rq = requests.put("https://novus.systems/api/BanlistsAPI/",json=data, headers=auth) answer = rq.json() return answer
Permission
Public

Edit | Back to List