diff --git a/brawlstars/__init__.py b/brawlstars/__init__.py index 69e3d6d..5ab60f9 100644 --- a/brawlstars/__init__.py +++ b/brawlstars/__init__.py @@ -1,6 +1,7 @@ from .client import * from .asyncclient import * from .errors import * +from .staticdata import * __author__ = 'Umbresp' __title__ = 'brawlstars' diff --git a/brawlstars/staticdata.py b/brawlstars/staticdata.py new file mode 100644 index 0000000..4934dbe --- /dev/null +++ b/brawlstars/staticdata.py @@ -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 '' + + 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 '' + +class Mode(Box): + + def __str__(self): + return 'Mode ' + self.name + + def __repr__(self): + return '' + +class Map(Box): + + def __str__(self): + return 'Map ' + self.name + + def __repr__(self): + return '' + + def get_mode(self): + mode = self.mode + mode = Box(mode) + mode = Mode(mode) + return mode \ No newline at end of file diff --git a/docs/infobrawler.md b/docs/infobrawler.md new file mode 100644 index 0000000..a630ac9 --- /dev/null +++ b/docs/infobrawler.md @@ -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 | +|--------|-------------|---------| diff --git a/docs/map.md b/docs/map.md new file mode 100644 index 0000000..93cca2e --- /dev/null +++ b/docs/map.md @@ -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. \ No newline at end of file diff --git a/docs/mode.md b/docs/mode.md new file mode 100644 index 0000000..c01156a --- /dev/null +++ b/docs/mode.md @@ -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. \ No newline at end of file diff --git a/docs/reference.md b/docs/reference.md index 4381a79..975ac50 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -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. diff --git a/docs/staticdata.md b/docs/staticdata.md new file mode 100644 index 0000000..535424b --- /dev/null +++ b/docs/staticdata.md @@ -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. \ No newline at end of file