wl_api

a wrapper library for the Warlight API


Keywords
warlight, wrapper, api, api-wrapper, published, pypi, wl-api
License
Other
Install
pip install wl_api==0.1.5

Documentation

wl_api

PyPI Version Build Status Code Climate Test Coverage Issue Count Codacy Badge

wrapper functions for the Warlight API

Installation

Latest release at https://github.com/knyte/wl_api/tarball/0.1.5

Install via pip (recommended):

pip install wl_api

Usage

1. Install dependencies

Don't worry about this if you installed using pip

pip install -r requirements.txt 

OR

python setup.py install # installs the whole module

(execute either command from the wl_api parent directory)

2. Import

import wl_api

3. Authenticate

email = "your@email.com"
password = "secret"
handler = wl_api.makeAPIHandler(email, password)

4. Use

Now you can use the functions corresponding to API endpoints like queryGame and deleteGame; use help() to get the parameters and help documentation for functions you want to use

Official Warlight API Documentation

https://www.warlight.net/wiki/Category:API

Basic Example Usage

from wl_api import *
    
email = "my@email.com"
password = "secret" # don't put your password in a plain Python file
   
handler = makeAPIHandler(email, password)
    
# or suppose I knew my token
token = "token"
    
handler = APIHandler(email, token)
    
# Let's query an existing game
gameID = 1234
gameData = handler.queryGame(gameID)
# Want to get history and settings too?
gameData = handler.queryGame(gameID, getHistory=True, getSettings=True)
    
# How about creating a game?
template = 1
gameName = "Test Game"
teams = [3022124041, (2, 3)] # 1 vs. 2
message = "Hi this is a test game"
game = handler.createGame(template, gameName, teams, message=message)
# game is the game ID of this new game
    
# Okay, now let's delete it - quick, before it leaves the lobby!
handler.deleteGame(game)
    
# Check games in a tournament
tourney_games = handler.getGameIDs("tournament", 4)
    
# Or a ladder
ladder_games = handler.getGameIDs("ladder", 4001)
# these both return a list of game ID's
    
# I wonder if I can play on template 12
myInfo = handler.validateToken(3022124041, 12)

You can get better explanations of both parameters and output by using help(APIHandler) and consulting the official Warlight documentation.