Skip to content

Commit 4f3110a

Browse files
committed
local lb, battle logs tests+docs
1 parent 59687fd commit 4f3110a

File tree

9 files changed

+118
-13
lines changed

9 files changed

+118
-13
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
__pycache__/
99
*.py[cod]
1010
*$py.class
11+
*.pyc
1112

1213
# C extensions
1314
*.so
@@ -110,5 +111,3 @@ ENV/
110111

111112
# mypy
112113
.mypy_cache/
113-
114-
*/__pycache__/

CHANGELOG.md

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

4+
## [2.3.12] - 7/18/19
5+
### Added
6+
- Player battle logs
7+
- Local leaderboards
8+
49
## [2.3.11] - 7/3/19
510
### Fixed
611
- Fixed the sync version of the wrapper to not raise a RuntimeWarning due to using `asyncio.sleep()` instead of `time.sleep()`

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Brawl Stats
2020
:target: https://github.com/SharpBit/brawlstats/blob/master/LICENSE
2121
:alt: MIT License
2222

23-
| This library is a sync and async wrapper the unofficial `Brawl Stars API`_.
24-
| Python 3.5.3 or later is required.
25-
| To keep up with API changes, discussions, and status, I recommend you join the API's `discord server`_.
23+
- This library is a sync and async wrapper the unofficial `Brawl Stars API`_.
24+
- Python 3.5.3 or later is required.
25+
- To keep up with API changes, discussions, and status, I recommend you join the API's `discord server`_.
2626

2727
Features
2828
~~~~~~~~

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.11'
11+
__version__ = 'v2.3.12'
1212
__title__ = 'brawlstats'
1313
__license__ = 'MIT'
1414
__author__ = 'SharpBit'

brawlstats/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def get_club(self, tag: bstag):
218218

219219
return self._get_model(url, model=Club)
220220

221-
def get_leaderboard(self, lb_type: str, count: int=200):
221+
def get_leaderboard(self, lb_type: str, count: int=200, region='global'):
222222
"""Get the top count players/clubs/brawlers.
223223
224224
Parameters
@@ -237,9 +237,9 @@ def get_leaderboard(self, lb_type: str, count: int=200):
237237
raise ValueError("Make sure 'count' is an int")
238238
if lb_type not in self.api.BRAWLERS + ['players', 'clubs'] or not 0 < count <= 200:
239239
raise ValueError("Please enter 'players', 'clubs' or a brawler or make sure 'count' is between 1 and 200.")
240-
url = '{}/{}?count={}'.format(self.api.LEADERBOARD, lb_type, count)
240+
url = '{}/{}?count={}&region={}'.format(self.api.LEADERBOARD, lb_type, count, region)
241241
if lb_type in self.api.BRAWLERS:
242-
url = '{}/players?count={}&brawlers={}'.format(self.api.LEADERBOARD, count, lb_type)
242+
url = '{}/players?count={}&brawlers={}&region={}'.format(self.api.LEADERBOARD, count, lb_type, region)
243243

244244
return self._get_model(url, model=Leaderboard)
245245

brawlstats/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def __init__(self, base_url):
1212
self.LEADERBOARD = self.BASE + '/leaderboards'
1313
self.EVENTS = self.BASE + '/events'
1414
self.MISC = self.BASE + '/misc'
15-
self.BATTLELOG = self.BASE + '/player/battlelog'
16-
self.CLUB_SEARCH = self.BASE + '/club/search'
15+
self.BATTLELOG = self.PROFILE + '/battlelog'
16+
self.CLUB_SEARCH = self.CLUB + '/search'
1717
self.CONSTANTS = 'https://fourjr.herokuapp.com/bs/constants/'
1818
self.BRAWLERS = [
1919
'shelly', 'nita', 'colt', 'bull', 'jessie', # league reward 0-500

docs/api.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Data Models
2828
.. autoclass: brawlstats.models.MiscData
2929
:members:
3030
31+
.. autoclass: brawlstats.models.BattleLog
32+
:members:
33+
3134
Player
3235
-------
3336

@@ -264,7 +267,95 @@ Name Type
264267
``server_date_day_of_year`` int
265268
===================================== ====
266269

270+
Battle Logs
271+
-----------
272+
273+
Returns a list of `BattleLog` that has the following attributes:
274+
275+
Attributes:
267276

277+
::
278+
279+
{
280+
"battleTime":"20190706T151526.000Z",
281+
"event":{
282+
"id":15000126,
283+
"mode":"duoShowdown",
284+
"map":"Royal Runway"
285+
},
286+
"battle":{
287+
"mode":"duoShowdown",
288+
"type":"ranked",
289+
"rank":1,
290+
"trophyChange":9,
291+
"teams":[
292+
[
293+
{
294+
"tag":"#Y2QPGG",
295+
"name":"Lex_YouTube",
296+
"brawler":{
297+
"id":16000005,
298+
"name":"SPIKE",
299+
"power":10,
300+
"trophies":495
301+
}
302+
},
303+
{
304+
"tag":"#8Q229LJY",
305+
"name":"Brandon",
306+
"brawler":{
307+
"id":16000003,
308+
"name":"BROCK",
309+
"power":10,
310+
"trophies":495
311+
}
312+
},
313+
{
314+
"tag":"#29RGL0QJ0",
315+
"name":"smallwhitepeen1",
316+
"brawler":{
317+
"id":16000007,
318+
"name":"JESSIE",
319+
"power":7,
320+
"trophies":486
321+
}
322+
}
323+
],
324+
[
325+
{
326+
"tag":"#CYLVL8LY",
327+
"name":"TST|ROYER™",
328+
"brawler":{
329+
"id":16000019,
330+
"name":"PENNY",
331+
"power":8,
332+
"trophies":541
333+
}
334+
},
335+
{
336+
"tag":"#8P2URCR0",
337+
"name":"ANOTHER",
338+
"brawler":{
339+
"id":16000023,
340+
"name":"LEON",
341+
"power":8,
342+
"trophies":559
343+
}
344+
},
345+
{
346+
"tag":"#8LRY92QP",
347+
"name":"Marshmello",
348+
"brawler":{
349+
"id":16000021,
350+
"name":"GENE",
351+
"power":7,
352+
"trophies":448
353+
}
354+
}
355+
]
356+
]
357+
}
358+
}
268359

269360
.. _Club: https://brawlstats.readthedocs.io/en/latest/api.html#id1
270361
.. _PartialClub: https://brawlstats.readthedocs.io/en/latest/api.html#id2

tests/test_async.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ async def test_get_club(self):
4242
async def test_get_leaderboard_player(self):
4343
lb = await self.client.get_leaderboard('players')
4444
self.assertTrue(isinstance(lb, brawlstats.Leaderboard))
45+
region = await self.client.get_leaderboard('players', region='us')
46+
self.assertTrue(isinstance(region, brawlstats.Leaderboard))
4547

4648
async def test_get_leaderboard_club(self):
4749
lb = await self.client.get_leaderboard('clubs')
@@ -74,6 +76,10 @@ async def test_club_search(self):
7476
search = await self.client.search_club('Penguin Raft')
7577
self.assertTrue(isinstance(search, list))
7678

79+
async def test_battle_logs(self):
80+
logs = await self.client.get_battle_logs(self.player_tag)
81+
self.assertTrue(isinstance(logs, list))
82+
7783
# Other
7884
async def test_invalid_tag(self):
7985
async def request():

tests/test_blocking.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def setUp(self):
2424
TOKEN,
2525
is_async=False,
2626
timeout=30,
27-
prevent_ratelimit=True,
2827
debug=True
2928
)
3029
logging.basicConfig(level=logging.DEBUG)
@@ -44,6 +43,8 @@ def test_get_club(self):
4443
def test_get_leaderboard_player(self):
4544
lb = self.client.get_leaderboard('players')
4645
self.assertTrue(isinstance(lb, brawlstats.Leaderboard))
46+
region = self.client.get_leaderboard('players', region='us')
47+
self.assertTrue(isinstance(region, brawlstats.Leaderboard))
4748

4849
def test_get_leaderboard_club(self):
4950
lb = self.client.get_leaderboard('clubs')
@@ -72,9 +73,12 @@ def test_get_misc(self):
7273

7374
def test_club_search(self):
7475
search = self.client.search_club('Penguin Raft')
75-
print(search)
7676
self.assertTrue(isinstance(search, list))
7777

78+
def test_battle_logs(self):
79+
logs = self.client.get_battle_logs(self.player_tag)
80+
self.assertTrue(isinstance(logs, list))
81+
7882
# Other
7983
def test_invalid_tag(self):
8084
get_profile = self.client.get_profile

0 commit comments

Comments
 (0)