Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
umbresp committed Mar 4, 2018
1 parent 2d99172 commit 73c5c55
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 1 deletion.
1 change: 1 addition & 0 deletions brawlstars/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .client import *
from .asyncclient import *
from .errors import *
from .staticdata import *

__author__ = 'Umbresp'
__title__ = 'brawlstars'
Expand Down
194 changes: 194 additions & 0 deletions brawlstars/staticdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import requests
from box import Box
from .errors import Error, ArgError, MissingArg, InvalidArg, HTTPError, Timeout, MissingData
import json

class StaticData:

def __init__(self, timeout=5):
self.timeout = timeout
self._base_url = "https://brawlapi.axaygadekar.me/api/"

def __str__(self):
return 'BrawlStars StaticData Object'

def __repr__(self):
return '<BrawlStars StaticData Object>'

def get_brawlers(self):
try:
resp = requests.get(self._base_url + 'brawlers', timeout=self.timeout)
if resp.status_code == 200:
data = resp.json()
elif 500 > resp.status_code > 400:
raise HTTPError(resp.status_code)
else:
raise Error()
except ValueError:
raise MissingData('data')
except:
raise Timeout()

brawlers = []
for brawler in data:
brawler = Box(brawler)
brawler = InfoBrawler(brawler)
brawlers.append(brawler)

return brawlers

def get_brawler(self, name):
brawlers = ['shelly', 'colt', 'nita', 'el_primo', 'dynamike',
'barley', 'bo', 'crow', 'spike', 'tara', 'mortis',
'bull', 'pam', 'piper', 'poco', 'ricochet', 'darryl',
'brock', 'jessie']

if name.lower().replace(" ", "_") == "shelly":
name = "shelley" # fuck u axay u misspelled it
if name.lower().replace(" ", "_") not in brawlers:
raise InvalidArg('name')

try:
resp = requests.get(self._base_url + 'brawlers/' + name.lower().replace(" ", "_"), timeout=self.timeout)
if resp.status_code == 200:
data = resp.json()
elif 500 > resp.status_code > 400:
raise HTTPError(resp.status_code)
else:
raise Error()
except ValueError:
raise MissingData('data')
except:
raise Timeout()

data = Box(data)
data = InfoBrawler(data)
return data

def get_modes(self):
try:
resp = requests.get(self._base_url + 'modes', timeout=self.timeout)
if resp.status_code == 200:
data = resp.json()
elif 500 > resp.status_code > 400:
raise HTTPError(resp.status_code)
else:
raise Error()
except ValueError:
raise MissingData('data')
except:
raise Timeout()

modes = []
for mode in data:
mode = Box(mode)
mode = Mode(mode)
modes.append(mode)

return modes

def get_mode(self, name):
modes = ['robo_rumble', 'boss_fight', 'showdown', 'bounty', 'smash_grab', 'heist', 'brawl_ball']
sng = ['sng', 'smashngrab', 'smash_n_grab', 'smash_&_grab', 'smash&grab', 'smash_and_grab']
if name.lower().replace(" ", "_") in sng:
name = 'smash_grab'
if name.lower().replace(" ", "_") not in modes:
raise InvalidArg('name')

try:
resp = requests.get(self._base_url + 'modes/' + name.lower().replace(" ", "_"), timeout=self.timeout)
if resp.status_code == 200:
data = resp.json()
elif 500 > resp.status_code > 400:
raise HTTPError(resp.status_code)
else:
raise Error()
except ValueError:
raise MissingData('data')
except:
raise Timeout()

data = Box(data)
data = Mode(data)
return data

def get_maps(self):
try:
resp = requests.get(self._base_url + 'maps', timeout=self.timeout)
if resp.status_code == 200:
data = resp.json()
elif 500 > resp.status_code > 400:
raise HTTPError(resp.status_code)
else:
raise Error()
except ValueError:
raise MissingData('data')
except:
raise Timeout()

maps = []
for map_ in data:
map_ = Box(map_)
map_ = Map(map_)
maps.append(map_)

return maps

def get_map(self, name):
maps = ['gg_corral', 'bandit_stash', 'kaboom_canyon', 'safe_zone', 'feast_famine',
'skull_creek', 'death_valley', 'stormy_plains', 'calamity_canyon', 'star_gulch',
'snake_prairie', 'shooting_star', 'outlaw_camp', 'groundhog_burrow', 'temple_ruins',
'terracotta_square', 'cabbage_patch', 'bone_box', 'temple_cacatombs', 'deep_hollows',
'hard_rock_mine', 'crystal_cavern', 'mushroom_cave', 'backyard_bowl', 'pinhole_punt',
'triple_dribble', 'pachinko_park']
ggc = ['gg_corral', 'g_g_corral', 'g._g._corral', 'g.g.corral']
if name.lower().replace(" ", "_") in ggc:
name = 'gg_corral'
if name.lower().replace(" ", "_") not in maps:
raise InvalidArg('name')

try:
resp = requests.get(self._base_url + 'maps/' + name.lower().replace(" ", "_"), timeout=self.timeout)
if resp.status_code == 200:
data = resp.json()
elif 500 > resp.status_code > 400:
raise HTTPError(resp.status_code)
else:
raise Error()
except ValueError:
raise MissingData('data')
except:
raise Timeout()

data = Box(data)
data = Map(data)
return data
class InfoBrawler(Box):

def __str__(self):
return 'InfoBrawler ' + self.name

def __repr__(self):
return '<InfoBrawler ' + self.name + '>'

class Mode(Box):

def __str__(self):
return 'Mode ' + self.name

def __repr__(self):
return '<Mode ' + self.name + '>'

class Map(Box):

def __str__(self):
return 'Map ' + self.name

def __repr__(self):
return '<Map ' + self.name + '>'

def get_mode(self):
mode = self.mode
mode = Box(mode)
mode = Mode(mode)
return mode
28 changes: 28 additions & 0 deletions docs/infobrawler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# InfoBrawler extends Box

(All methods and attributes of Box automatically belong to InfoBrawler.)

## Creating an InfoBrawler
The only way to create a InfoBrawler is to use get it from brawlstars.StaticData. Example:
```py
import brawlstars
data = brawlstars.StaticData()
brawler = data.get_brawler('shelly')
```

## InfoBrawler Attributes
| Variable | Description | Type |
|----------|-------------|------|
| name | The name of the brawler. | string |
| description | The brawler's description. | string |
| type | Ranged or melee. | string |
| tier | The rarity of the brawler. | string |
| speed | The speed of the brawler. | string |
| hitpoints | The base amount of HP the brawler has. | integer |
| image | A relative link to the image for the brawler. | string |
| thumb_image | A relative link to the thumb for the brawler. | string |
| link | A link to the api page about the brawler. | string |

## InfoBrawler Methods
| Method | Description | Returns |
|--------|-------------|---------|
25 changes: 25 additions & 0 deletions docs/map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Map extends Box

(All methods and attributes of Box automatically belong to Map.)

## Creating an Map
The only way to create a Map is to use get it from brawlstars.StaticData. Example:
```py
import brawlstars
data = brawlstars.StaticData()
map = data.get_map('skull_creek')
```

## Map Attributes
| Variable | Description | Type |
|----------|-------------|------|
| name | The name of the map. | string |
| description | The map's description. | string |
| link | A link to the api page about the map. | string |

## Map Methods
| Method | Description | Returns |
|--------|-------------|---------|
| get_mode() | Gets the mode the map belongs to. | Mode\* |

\*When creating a Mode with Map, the description will be unavailable.
24 changes: 24 additions & 0 deletions docs/mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Mode extends Box

(All methods and attributes of Box automatically belong to Mode.)

## Creating an Mode
The only way to create a Mode is to use get it from brawlstars.StaticData or brawlstars.StaticData.map\*. Example:
```py
import brawlstars
data = brawlstars.StaticData()
mode = data.get_mode('showdown')
```

## Mode Attributes
| Variable | Description | Type |
|----------|-------------|------|
| name | The name of the mode. | string |
| description | The mode's description. | string |
| link | A link to the api page about the mode. | string |

## Mode Methods
| Method | Description | Returns |
|--------|-------------|---------|

\*When creating a Mode with Map, the description will be unavailable.
5 changes: 4 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ Here's a list with a link to a file for every class in the wrapper because I'm *
- [Client](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/client.md)
- [Errors](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/errors.md)
- [Id](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/id.md)
- [InfoBrawler](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/infobrawler.md)
- [Map](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/map.md)
- [Mode](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/mode.md)
- [Member](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/member.md)
- [MinimalBand](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/minimalband.md)
- [Player](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/player.md)
- [PlayerLeaderboard](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/playerleaderboard.md)
- [RankedBand](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/rankedband.md)
- [RankedPlayer](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/rankedplayer.md)
- [StaticData](https://github.com/umbresp/brawlstars/blob/master/brawlstars/docs/staticdata.md)

\*Not finished yet.
31 changes: 31 additions & 0 deletions docs/staticdata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# StaticData
StaticData is an object which contains all the static info about the game (in progress). Credit for the descriptions goes to axaygadekhar.

## Creating a StaticData
`data = brawlstars.StaticData(*args, **kwargs)`

| Argument | Description | Type |
|----------|-------------|------|
| timeout* | How long to wait for response. | integer |

\*optional

## StaticData Attributes
| Variable | Description | Type |
|----------|-------------|------|
| \_base\_url* | Base URL to make requests to. | string |
| timeout | How long to wait for response. | integer |

\*immutable

## StaticData Methods
| Method | Description | Returns |
|--------|-------------|---------|
| get_brawlers() | Get information about all the brawlers. | List of InfoBrawler\* |
| get_brawler(name) | Get information about a brawler. | InfoBrawler\* |
| get_maps() | Get information about all the maps. | List of Map |
| get_map(name) | Get information about a map. | Map |
| get_modes() | Get information about all the modes. | List of Mode |
| get_mode(name) | Get information about a mode. | Mode |

\*Not to be confused with Brawler.

0 comments on commit 73c5c55

Please sign in to comment.