Skip to content

Commit ccbca58

Browse files
committed
add rosa, prevent_ratelimit, update URLs
1 parent 8d93d4b commit ccbca58

8 files changed

Lines changed: 34 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## [2.3.6] - 4/27/19
5+
### Added
6+
- Rosa to the brawler list
7+
- `prevent_ratelimit` option when initializing a client to wait when chaining requests
8+
### Changed
9+
- Base URL for requests to [the new API URL](https://api.brawlapi.cf/v1)
10+
- Ratelimit updated to API's 3 requests per second
11+
412
## [2.3.5] - 4/15/19
513
### Fixed
614
- Fixed the rate limit handler when error code 429 was returned by the API.

README.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Brawl Stats
2121
:alt: MIT License
2222

2323
| This library is a sync and async wrapper the unofficial `Brawl Stars API`_.
24-
| To keep up with API changes, discussions, and status, I recommend you join the `discord server`_.
24+
| To keep up with API changes, discussions, and status, I recommend you join the API's `discord server`_.
2525
2626
Features
2727
~~~~~~~~
@@ -64,16 +64,17 @@ Misc
6464

6565
| If you are currently using this wrapper, feel free to star this repository :)
6666
| If you come across an issue in the wrapper, please `create an issue`_. Do **not** PM me on Discord for help.
67-
| If you need an API Key, join the API’s `discord server`_.
67+
| If you need an API Key, create one using the `dashboard`_.
6868
6969
Contributing
7070
~~~~~~~~~~~~
7171
If you want to contribute, whether it be a bug fix or new feature, make sure to follow the `contributing guidelines`_.
7272

73-
.. _Brawl Stars API: http://brawlapi.cf/api
73+
.. _Brawl Stars API: https://api.brawlapi.cf/v1
7474
.. _create an issue: https://github.com/SharpBit/brawlstats/issues
7575
.. _discord server: https://discord.me/BrawlAPI
7676
.. _Read the Docs: https://brawlstats.rtfd.io/
7777
.. _examples folder: https://github.com/SharpBit/brawlstats/tree/master/examples
7878
.. _discord.py rewrite: https://github.com/rapptz/discord.py/tree/rewrite
79-
.. _contributing guidelines: https://github.com/SharpBit/brawlstats/blob/master/CONTRIBUTING.md
79+
.. _contributing guidelines: https://github.com/SharpBit/brawlstats/blob/master/CONTRIBUTING.md
80+
.. _dashboard: https://brawlapi.cf/dashboard

brawlstats/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
############
99

1010

11-
__version__ = 'v2.3.5'
11+
__version__ = 'v2.3.6'
1212
__title__ = 'brawlstats'
1313
__license__ = 'MIT'
1414
__author__ = 'SharpBit'

brawlstats/constants.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

brawlstats/core.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Client:
2424
Parameters
2525
------------
2626
token: str
27-
The API Key that you can get from https://discord.me/BrawlAPI
27+
The API Key that you can get from https://brawlapi.cf/dashboard
2828
session: Optional[Session] = None
2929
Use a current session or a make new one. Can be ``aiohttp.ClientSession()`` or ``requests.Session()``
3030
timeout: Optional[int] = 10
@@ -42,6 +42,9 @@ class Client:
4242
Whether or not to give you more info to debug easily.
4343
base_url: Optional[str] = None
4444
Sets a different base URL to make request to. Only use this if you know what you are doing.
45+
prevent_ratelimit: Optional[bool] = False
46+
Whether or not you want to wait for a small amount of time between requests to prevent being ratelimited.
47+
Recommended if you are performing multiple requests in a short period of time.
4548
"""
4649

4750
REQUEST_LOG = '{method} {url} recieved {text} has returned {status}'
@@ -54,10 +57,13 @@ def __init__(self, token, session=None, timeout=10, is_async=False, **options):
5457
aiohttp.ClientSession(loop=self.loop, connector=self.connector) if self.is_async else requests.Session()
5558
)
5659
self.timeout = timeout
60+
self.lock = asyncio.Lock() if options.get('prevent_ratelimit') is True else None
5761
self.api = API(options.get('base_url'))
62+
5863
self.debug = options.get('debug', False)
5964
self.cache = TTLCache(900, 180) # 5 requests/sec
60-
self.ratelimit = [5, 5, 0] # per second, remaining, time until reset
65+
self.ratelimit = [3, 3, 0] # per second, remaining, time until reset
66+
6167
self.headers = {
6268
'Authorization': token,
6369
'User-Agent': 'brawlstats/{0} (Python {1[0]}.{1[1]})'.format(self.api.VERSION, sys.version_info),
@@ -148,7 +154,13 @@ def _request(self, url):
148154
return data
149155

150156
async def _aget_model(self, url, model, key=None):
151-
data, resp = await self._arequest(url)
157+
if self.lock is not None:
158+
async with self.lock:
159+
data, resp = await self._arequest(url)
160+
await asyncio.sleep(1 / self.ratelimit[0])
161+
else:
162+
data, resp = await self._arequest(url)
163+
152164
if model == Constants:
153165
if key and not data.get(key):
154166
raise KeyError('No such key for Brawl Stars constants "{}"'.format(key))

brawlstats/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __getattr__(self, attr):
2626
try:
2727
return super().__getattr__(attr)
2828
except AttributeError:
29-
return None # makes it easier on the user's end
29+
return None # users can use an if statement rather than try/except to find a missing attribute
3030

3131
def __getitem__(self, item):
3232
try:

brawlstats/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class API:
88
def __init__(self, base_url):
9-
self.BASE = base_url or 'https://brawlapi.cf/api'
9+
self.BASE = base_url or 'https://api.brawlapi.cf/v1'
1010
self.PROFILE = self.BASE + '/player'
1111
self.CLUB = self.BASE + '/club'
1212
self.LEADERBOARD = self.BASE + '/leaderboards'
@@ -17,7 +17,7 @@ def __init__(self, base_url):
1717
self.BRAWLERS = [
1818
'shelly', 'nita', 'colt', 'bull', 'jessie', # league reward 0-500
1919
'brock', 'dynamike', 'bo', # league reward 1000+
20-
'el primo', 'barley', 'poco', # rare
20+
'el primo', 'barley', 'poco', 'rosa', # rare
2121
'ricochet', 'penny', 'darryl', 'carl', # super rare
2222
'frank', 'pam', 'piper', # epic
2323
'mortis', 'tara', 'gene', # mythic

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Welcome to Brawl Stats' documentation!
1414
:alt: MIT License
1515

1616
| Brawl Stats is an easy to use async wrapper for the unofficial `Brawl Stars API`_.
17-
| Please note that both this API and wrapper are both still in beta, so there will be frequent breaking changes.
17+
| To keep up with API changes, discussions, and status, I recommend you join the API's `discord server`_.
1818
1919
Features
2020
~~~~~~~~

0 commit comments

Comments
 (0)