Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 1927f29

Browse files
committed
Update, date - Wed 07/20/2022, time - 0:19:57.47
1 parent 8ea1284 commit 1927f29

File tree

2 files changed

+227
-33
lines changed

2 files changed

+227
-33
lines changed

README.rst

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ Below are the available sub classes:
9393
+-------------------+----------+
9494
|* `Me`_ | other |
9595
+-------------------+----------+
96+
|* `Shop`_ | other |
97+
+-------------------+----------+
9698
|* `Misc`_ | other |
9799
+-------------------+----------+
98100

@@ -165,6 +167,20 @@ For a detailed description, ``__doc__`` (docstring) of each sub class can be cal
165167
# print out the docstring
166168
print(api.Me.__doc__)
167169
170+
.. _`Shop`:
171+
172+
``Shop``:
173+
174+
.. code-block:: python
175+
176+
from cod_api import API
177+
178+
api = API()
179+
180+
# print out the docstring
181+
print(api.Shop.__doc__)
182+
183+
168184
.. _`Misc`:
169185

170186
``Misc``:
@@ -418,3 +434,157 @@ Available ``platforms`` are as follows:
418434
platforms.Uno # Uno (activision unique id)
419435
420436
platforms.XBOX # Xbox
437+
438+
User Info
439+
----------
440+
441+
Using the ``info()`` method in sub class ``Me`` of ``API`` user information can be retrieved of the sso-token logged in
442+
with
443+
444+
.. code-block:: python
445+
446+
from cod_api import API
447+
448+
# initiating the API class
449+
api = API()
450+
451+
# loggin in with sso token
452+
api.login('your_sso_token')
453+
454+
# retrieving user info
455+
userInfo = api.Me.info() # returns data of type dict
456+
457+
# printing results to console
458+
print(userInfo)
459+
460+
User Friend Feed
461+
----------------
462+
463+
Using the ``friendFeed()`` method in sub class ``Me`` of ``API`` user's friend feed can be retrieved of the sso-token
464+
logged in with
465+
466+
.. code-block:: python
467+
468+
from cod_api import API
469+
470+
# initiating the API class
471+
api = API()
472+
473+
# loggin in with sso token
474+
api.login('your_sso_token')
475+
476+
# retrieving user friend feed
477+
friendFeed = api.Me.friendFeed() # returns data of type dict
478+
479+
# printing results to console
480+
print(friendFeed)
481+
482+
User Event Feed
483+
----------------
484+
485+
Using the ``eventFeed()`` method in sub class ``Me`` of ``API`` user's event feed can be retrieved of the sso-token
486+
logged in with
487+
488+
.. code-block:: python
489+
490+
from cod_api import API
491+
492+
# initiating the API class
493+
api = API()
494+
495+
# loggin in with sso token
496+
api.login('your_sso_token')
497+
498+
# retrieving user event feed
499+
eventFeed = api.Me.eventFeed() # returns data of type dict
500+
501+
# printing results to console
502+
print(eventFeed)
503+
504+
User Identities
505+
----------------
506+
507+
Using the ``loggedInIdentities()`` method in sub class ``Me`` of ``API`` user's identities can be retrieved of the
508+
sso-token logged in with
509+
510+
.. code-block:: python
511+
512+
from cod_api import API
513+
514+
# initiating the API class
515+
api = API()
516+
517+
# loggin in with sso token
518+
api.login('your_sso_token')
519+
520+
# retrieving user identities
521+
identities = api.Me.loggedInIdentities() # returns data of type dict
522+
523+
# printing results to console
524+
print(identities)
525+
526+
User COD Points
527+
----------------
528+
529+
Using the ``codPoints()`` method in sub class ``Me`` of ``API`` user's cod points can be retrieved of the sso-token
530+
logged in with
531+
532+
.. code-block:: python
533+
534+
from cod_api import API
535+
536+
# initiating the API class
537+
api = API()
538+
539+
# loggin in with sso token
540+
api.login('your_sso_token')
541+
542+
# retrieving user cod points
543+
cp = api.Me.codPoints() # returns data of type dict
544+
545+
# printing results to console
546+
print(cp)
547+
548+
User Accounts
549+
----------------
550+
551+
Using the ``connectedAccounts()`` method in sub class ``Me`` of ``API`` user's connected accounts can be retrieved of
552+
the sso-token logged in with
553+
554+
.. code-block:: python
555+
556+
from cod_api import API
557+
558+
# initiating the API class
559+
api = API()
560+
561+
# loggin in with sso token
562+
api.login('your_sso_token')
563+
564+
# retrieving user connected accounts
565+
accounts = api.Me.codPoints() # returns data of type dict
566+
567+
# printing results to console
568+
print(accounts)
569+
570+
User settings
571+
----------------
572+
573+
Using the ``settings()`` method in sub class ``Me`` of ``API`` user's settings can be retrieved of the sso-token logged
574+
in with
575+
576+
.. code-block:: python
577+
578+
from cod_api import API
579+
580+
# initiating the API class
581+
api = API()
582+
583+
# loggin in with sso token
584+
api.login('your_sso_token')
585+
586+
# retrieving user settings
587+
settings = api.Me.settings() # returns data of type dict
588+
589+
# printing results to console
590+
print(settings)

cod_api/__init__.py

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ async def __sendRequest(self, url: str):
174174
if respond.status_code == 200:
175175
data = respond.json()
176176
if data['status'] == 'success':
177-
return data['data']
177+
data = self.__mapping(data['data'])
178+
return data
178179
else:
179180
sys.exit(StatusError())
180181
else:
@@ -209,6 +210,29 @@ def __helper(self, platform, gamertag):
209210
gamertag = self.__cleanClientName(gamertag)
210211
return lookUpType, gamertag
211212

213+
# mapping
214+
def __mapping(self, data):
215+
r = requests.get('https://engineer152.github.io/wz-data/weapon-ids.json')
216+
guns = r.json()['All Weapons']
217+
r = requests.get('https://engineer152.github.io/wz-data/game-modes.json')
218+
modes = r.json()['modes']
219+
220+
# guns
221+
try:
222+
for m in data['matches']:
223+
for l in m['player']['loadouts']:
224+
if l['primaryWeapon']['label'] is None:
225+
l['primaryWeapon']['label'] = guns[l['primaryWeapon']['name']]
226+
227+
if l['secondaryWeapon']['label'] is None:
228+
l['secondaryWeapon']['label'] = guns[l['secondaryWeapon']['name']]
229+
except KeyError:
230+
pass
231+
except Exception as e:
232+
print(e)
233+
234+
return data
235+
212236
# API Requests
213237
async def __fullDataReq(self, game, platform, gamertag, type):
214238
lookUpType, gamertag = self.__helper(platform, gamertag)
@@ -490,37 +514,6 @@ def matchInfo(self, platform, matchId: int):
490514
data = asyncio.run(self._common__matchInfoReq("vg", platform, "mp", matchId))
491515
return data
492516

493-
494-
# SHOP
495-
class __SHOP(__common):
496-
"""
497-
Shop class: A class to get bundle details and battle pass loot
498-
classCatogery: other
499-
500-
Methods
501-
-------
502-
purchasableItems(game: games)
503-
returns purchasable items for a specific gameId/gameTitle
504-
505-
bundleInformation(game: games, bundleId: int)
506-
returns bundle details for the specific gameId/gameTitle and bundleId
507-
508-
battlePassLoot(game: games, platform: platforms, season: int)
509-
returns battle pass loot for specific game and season on given platform
510-
"""
511-
512-
def purchasableItems(self, game: games):
513-
data = asyncio.run(self._common__sendRequest(f"/inventory/v1/title/{game}/platform/psn/purchasable/public/en"))
514-
return data
515-
516-
def bundleInformation(self, game: games, bundleId: int):
517-
data = asyncio.run(self._common__sendRequest(f"/inventory/v1/title/{game}/bundle/{bundleId}/en"))
518-
519-
def battlePassLoot(self,game: games, platform: platforms, season: int):
520-
data = asyncio.run(self._common__sendRequest(f"/loot/title/{game}/platform/{platform.value}/list/loot_season_{season}/en"))
521-
return data
522-
523-
524517
# USER
525518
class __USER(__common):
526519
def info(self):
@@ -548,7 +541,7 @@ def __priv(self):
548541
d = self.info()
549542
return d['identities'][0]['platform'], quote(d['identities'][0]['gamertag'].encode("utf-8"))
550543

551-
def friendFeed(self, platform, gamertag:str):
544+
def friendFeed(self):
552545
p, g = self.__priv()
553546
data = asyncio.run(
554547
self._common__sendRequest(f"/userfeed/v1/friendFeed/platform/{p}/gamer/{g}/friendFeedEvents/en")
@@ -578,6 +571,37 @@ def settings(self):
578571
data = asyncio.run(self._common__sendRequest(f"/preferences/v1/platform/{p}/gamer/{g}/list"))
579572
return data
580573

574+
# SHOP
575+
class __SHOP(__common):
576+
"""
577+
Shop class: A class to get bundle details and battle pass loot
578+
classCatogery: other
579+
580+
Methods
581+
-------
582+
purchasableItems(game: games)
583+
returns purchasable items for a specific gameId/gameTitle
584+
585+
bundleInformation(game: games, bundleId: int)
586+
returns bundle details for the specific gameId/gameTitle and bundleId
587+
588+
battlePassLoot(game: games, platform: platforms, season: int)
589+
returns battle pass loot for specific game and season on given platform
590+
"""
591+
592+
def purchasableItems(self, game: games):
593+
data = asyncio.run(
594+
self._common__sendRequest(f"/inventory/v1/title/{game}/platform/uno/purchasable/public/en"))
595+
return data
596+
597+
def bundleInformation(self, game: games, bundleId: int):
598+
data = asyncio.run(self._common__sendRequest(f"/inventory/v1/title/{game}/bundle/{bundleId}/en"))
599+
600+
def battlePassLoot(self, game: games, platform: platforms, season: int):
601+
data = asyncio.run(self._common__sendRequest(
602+
f"/loot/title/{game}/platform/{platform.value}/list/loot_season_{season}/en"))
603+
return data
604+
581605
# ALT
582606
class __ALT(__common):
583607

0 commit comments

Comments
 (0)