-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
307 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | | ||
|--------|-------------|---------| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |