Also, here is the code I am using:
main.pyfrom api import *
from library import *
import random
def maker1():
players = [andrew, benjamin628, bilboswaggins, blobx, blortis, character, doge, drstupid, hankypinky, jayvan, jplatt821, jt, jz, kachan, legacy, legendofthephoenix, marsadpl, masterofdesaster, ppface, shyb, stealth90, thethedde, tschombawomba, yellowswag]
random.shuffle(players)
templates = [723061]
random.shuffle(templates)
email = "CENSORED"
password = "CENSORED"
token = getAPIToken(email, password)
template = templates[0] #Picks a random template
gameName = "--[AWF Ladder]--"
message = "Shoutout to ppface and kachan, without them this wouldn't be possible!"
for x in xrange(0, 1): #amount of games at one time
for x in xrange(0, len((players)/2)): #amount of games
teams = [players[((x+1)*2)-2] , players[((x+1)*2)-1]],
game = createGame(email, token, template=template, gameName=gameName, message=message, teams=teams)
print game
def maker2():
players2 = [andrew, benjamin628, bilboswaggins, blobx, blortis, doge, hankypinky, jammawind, jayvan, jplatt821, jt, jz, kachan, legacy, ppface, shyb, stealth90, thethedde, tschombawomba, yellowswag]
random.shuffle(players)
templates = [723061]
random.shuffle(templates)
email = "CENSORED"
password = "CENSORED"
token = getAPIToken(email, password)
template = templates[0] #Picks a random template
gameName = "--[AWF Ladder]--"
message = "Shoutout to ppface and kachan, without them this wouldn't be possible!"
for x in xrange(0, 1): #amount of games at one time
for x in xrange(0, len((players2)/4)): #amount of games
teams = [[players2[((x+1)*4)-4] , players2[((x+1)*4)-3]], [players2[((x+1)*4)-2] , players2[((x+1)*4)-1]]]
game = createGame(email, token, template=template, gameName=gameName, message=message, teams=teams)
print game
def maker3():
players3 = [andrew, benjamin628, bilboswaggins, blobx, blortis, doge, drstupid, hankypinky, jammawind, jayvan, jplatt821, jt, jz, kachan, legacy, legendofthephoenix, lordofshadows, masterofdesaster, ppface, shyb, stealth90, thethedde, tschombawomba, yellowswag]
random.shuffle(players)
templates = [723061]
random.shuffle(templates)
email = "CENSORED"
password = "CENSORED"
token = getAPIToken(email, password)
template = templates[0] #Picks a random template
gameName = "--[AWF Ladder]--"
message = "Shoutout to ppface and kachan, without them this wouldn't be possible!"
for x in xrange(0, 1): #amount of games at one time
for x in xrange(0, len((players3)/6)): #amount of games
teams = [players3[((x+1)*6)-6] , players3[((x+1)*6)-5], players3[((x+1)*6)-4]], [players3[((x+1)*6)-3] , players3[((x+1)*6)-2], players3[((x+1)*6)-1]]
game = createGame(email, token, template=template, gameName=gameName, message=message, teams=teams)
print game
api.py##############################
# COMMUNITY SUPPORTED LEAGUE #
#@author: knyte #
#@version: 0.1 #
#@license: MIT #
##############################
import requests
import string
class APIError(Exception):
"""
Error class that should simply output errors
raised by the Warlight API itself
"""
pass
def getNextID(ID):
"""
Given an ID, returns the next ID
"""
if ID[-1] == "Z":
newID = "A" * (len(ID) + 1)
else:
newID = chr(ord(ID) + 1)
def makePlayers(teams):
"""
Given teams, returns a list
containing player dictionaries
"""
teamID = 0
players = list()
for team in teams:
if (type(team) == list) or (type(team) == tuple):
for member in team:
player = dict()
player['token'] = str(member)
player['team'] = str(teamID)
players.append(player)
else:
player = dict()
player['token'] = str(team)
player['team'] = str(teamID)
players.append(player)
teamID += 1
return players
def overrideBonuses(bonuses):
"""
Given a list containing tuples
with bonus name and new values,
generates new list with said data
in dictionary form
"""
overridenBonuses = list()
for bonus in bonuses:
bonusData = dict()
bonusData['bonusName'] = bonus[0]
bonusData['value'] = bonus[1]
overridenBonuses.append(bonusData)
return overridenBonuses
def getAPIToken(email, password):
"""
Gets API token using email and password
"""
site = "https://www.warlight.net/API/GetAPIToken"
data = dict()
data['Email'] = email
data['Password'] = password
r = requests.post(url=site, params=data)
jsonOutput = r.json()
if 'error' in jsonOutput:
raise APIError(jsonOutput['error'])
return jsonOutput['APIToken']
def queryGame(email, token, gameID, getHistory=False):
"""
Queries a game given gameID
using credentials (email+token)
returns JSON output
"""
getHistory = str(getHistory).lower()
site = "https://www.warlight.net/API/GameFeed"
data = dict()
data['Email'] = email
data['APIToken'] = token
data['GameID'] = str(gameID)
data['GetHistory'] = getHistory
r = requests.post(url=site, params=data)
jsonOutput = r.json()
if 'error' in jsonOutput:
raise APIError(jsonOutput['error'])
return jsonOutput
def createGame(email, token, **settings):
"""
Creates a game given settings
using credentials (email+token)
returns game ID
"""
site = "https://www.warlight.net/API/CreateGame"
data = dict()
data['hostEmail'] = email
data['hostAPIToken'] = str(token)
data['templateID'] = settings.get('template')
data['gameName'] = settings.get('gameName')
data['personalMessage'] = settings.get('message')
teams = settings.get('teams')
data['players'] = makePlayers(teams)
if 'overriddenBonuses' in settings:
data['overridenBonuses'] = \
overrideBonuses(settings.get('overridenBonuses'))
r = requests.post(url=site, json=data)
jsonOutput = r.json()
if 'error' in jsonOutput:
raise APIError(jsonOutput['error'])
return jsonOutput['gameID']
def deleteGame(email, token, gameID):
"""
Deletes a game
using credentials (email+token)
does not return anything
"""
site = "https://www.warlight.net/API/DeleteLobbyGame"
data = dict()
data['Email'] = email
data['APIToken'] = str(token)
data['gameID'] = int(gameID)
r = requests.post(url=site, json=data)
jsonOutput = r.json()
if 'error' in jsonOutput:
raise APIError(jsonOutput['error'])
if 'success' not in jsonOutput:
raise APIError("Unknown error!")
def getGameIDs(email, token, *source):
"""
Gets a list of games for a ladder/tournament
using credentials (email+token)
returns list of games
"""
site = "https://www.warlight.net/API/GameIDFeed"
data = dict()
data['Email'] = email
data['APIToken'] = token
try:
assert(len(source) == 2)
except:
raise TypeError("Need both source type and ID!")
if ("ladder" in source) or ("Ladder" in source):
data['LadderID'] = int(source[-1])
elif ("tournament" in source) or ("Tournament" in source):
data['TournamentID'] = int(source[-1])
else:
raise IOError("Source type must be either ladder or tournament!")
r = requests.post(url=site, params=data)
jsonOutput = r.json()
if 'error' in jsonOutput:
raise APIError(jsonOutput['error'])
return jsonOutput['gameIDs']
def validateToken(email, token, player, *templates):
"""
Validtes an inviteToken
using credentials (email+token)
returns response
"""
site = "https://www.warlight.net/API/ValidateInviteToken"
data = dict()
data['Email'] = email
data['APIToken'] = token
data['Token'] = player
if templates is not tuple():
data['TemplateIDs'] = string.join(templates, ",")
r = requests.post(url=site, params=data)
jsonOutput = r.json()
if 'error' in jsonOutput:
raise APIError(jsonOutput['error'])
return jsonOutput
def setMapDetails(email, token, mapID, *commands):
"""
Sets map details
using credentials (email+token)
and command setup (commandtype, dict())
"""
site = "https://www.warlight.net/API/SetMapDetails"
data = dict()
data['email'] = email
data['APIToken'] = token
data['mapID'] = str(mapID)
commandData = list()
for command in commands:
order = dict()
order['command'] = command[0]
for item in command[1]:
order[item] = command[item]
commands.append(order)
data['commands'] = commandData
r = requests.post(url=site, json=data)
jsonOutput = r.json()
if 'error' in jsonOutput:
raise APIError(jsonOutput['error'])
Edited 11/24/2015 00:08:01