Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Major API Sets #1

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 DevRuby
Copyright (c) 2023 DevRuby

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,35 @@

![Tracker](https://static1-fr.millenium.gg/articles/9/34/23/09/@/1117224-111-article_m-1.jpg)

**TrackerGG is a Tracker API Client**
**An API Wrapper for [TrackerGG API](https://tracker.gg)**

## Install

```pip install TrackerGG```


## Use

[Sign in tracker.gg and get token](https://tracker.gg/developers)
Get API Key

**Example of getting csgo profile**
[TrackerGG Developers](https://tracker.gg/developers)


## **Quick Example**
```py
import TrackerGG # import this library
import asyncio # asyncio library for calling async function
import TrackerGG
import asyncio

client = TrackerGG.Client('TOKEN') # replace 'TOKEN' with your token value.

def GetSync(profile):
return client.get_csgo_profile(profile)
client = TrackerGG.CSGOClient("YOUR_API_KEY")

async def GetAsync(profile):
return await client.async_get_csgo_profile(profile)
profile = asyncio.run(client.get_profile("PLAYER_NAME OR ID"))

print(GetSync("DevRuby").stats.kills.value)
print(asyncio.run(GetAsync("DevRuby")).stats.kills.value)
print(profile.segments[0].stats[0])

```

## Exceptions
### ApiError
Incorrect Api Key
### UserError
Can't find the user
**Output**
```
Name : Time Played
Value : 1,236h
Percentile : 84.0
```
9 changes: 3 additions & 6 deletions TrackerGG/info.py → TrackerGG/Models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2021 DevRuby
Copyright (c) 2023 DevRuby

MIT License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

"""

__version__ = "1.0"
__author__ = "DevRuby"
__license__ = "MIT License"
__copyright__ = "(c) 2021 DevRuby"
from .csgo import CSGOProfile
34 changes: 34 additions & 0 deletions TrackerGG/Models/csgo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby

MIT License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

"""
from typing import Dict, Any, List

from .platform import PlatformInfo
from .segment import Segment
from .user import UserInfo


class CSGOProfile:
def __init__(self, data: Dict[str, Any]):
segments = []
for seg in data["segments"]:
segments.append(Segment(seg))

self.platform_info: PlatformInfo = PlatformInfo(data["platformInfo"])
self.user_info: UserInfo = UserInfo(data["userInfo"])
self.segments: List[Segment] = segments
self.expiry_date: str = data["expiryDate"]
46 changes: 46 additions & 0 deletions TrackerGG/Models/platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby

MIT License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

"""

from enum import Enum
from typing import Dict, Union, Any


class Platform(Enum):
steam = "steam"
origin = "origin"
xbl = "xbl"
psn = "psn"
uplay = "uplay"


class PlatformInfo:
def __init__(self, data: Dict[str, Union[str, int, None]]):
platforms = {
"steam": Platform.steam,
"origin": Platform.origin,
"xbl": Platform.xbl,
"psn": Platform.psn,
"uplay": Platform.uplay,
}

self.platform_slug: Platform = platforms[data["platformSlug"]]
self.platform_user_id: Union[str, int] = data["platformUserId"]
self.platform_user_handle: str = data["platformUserHandle"]
self.platform_user_identifier: Union[str, int] = data["platformUserIdentifier"]
self.avatar_url: str = data["avatarUrl"]
self.additional_parameters: Any = data["additionalParameters"]
49 changes: 49 additions & 0 deletions TrackerGG/Models/segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby

MIT License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

"""

from typing import List, Dict, Union, Any


class Stat:
def __init__(self, data: Dict[str, Union[int, float, str, None, dict]]):
self.rank: int = data["rank"]
self.percentile: float = data["percentile"]
self.display_name: str = data["displayName"]
self.display_category: str = data["displayCategory"]
self.category: Union[None, str] = data["category"]
self.description: str = data["description"]
self.metadata: Union[None, dict[str, Any]] = data["metadata"]
self.value: int = data["value"]
self.display_value: str = data["displayValue"]
self.display_type: str = data["displayType"]

def __str__(self):
return f"Name : {self.display_name}\nValue : {self.display_value}\nPercentile : {self.percentile}"


class Segment:
def __init__(self, data: Dict[str, Union[str, int, dict]]):
stats = []
for stat in data["stats"].keys():
stats.append(Stat(data["stats"][stat]))

self.type: str = data["type"]
self.attributes: dict = data["attributes"]
self.metadata: dict = data["metadata"]
self.expiry_date: str = data["expiryDate"]
self.stats: List[Stat] = stats
49 changes: 49 additions & 0 deletions TrackerGG/Models/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby

MIT License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

"""

from typing import Dict, Union, Optional, Any, List


class SocialAccount:
def __init__(self, data: Dict[str, Union[str, int, None]]):
self.platform_slug: str = data["platformSlug"]
self.platform_user_id: Union[str, int] = data["platformUserId"]
self.platform_user_handle: str = data["platformUserHandle"]
self.platform_user_identifier: Union[str, int] = data["platformUserIdentifier"]
self.avatar_url: str = data["avatarUrl"]
self.additional_parameters: Any = data["additionalParameters"]


class UserInfo:
def __init__(self, data: Dict[str, Union[str, int, bool, list, None]]):
social_accounts = []
if data["socialAccounts"]:
for social_account in data["socialAccounts"]:
social_accounts.append(SocialAccount(social_account))

self.user_id: Optional[int] = data["userId"]
self.is_premium: bool = data["isPremium"]
self.is_verified: bool = data["isVerified"]
self.is_influencer: bool = data["isInfluencer"]
self.is_partner: bool = data["isPartner"]
self.country_code: Union[str, None] = data["countryCode"]
self.custom_avatar_url: Optional[str] = data["customAvatarUrl"]
self.custom_hero_url: Optional[str] = data["customHeroUrl"]
self.social_accounts: List[SocialAccount] = social_accounts
self.page_views: int = data["pageviews"]
self.custom_avatar_url: Any = data["isSuspicious"]
18 changes: 4 additions & 14 deletions TrackerGG/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2021 DevRuby
Copyright (c) 2023 DevRuby

MIT License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

"""

from .exceptions import ApiError
from .exceptions import UserError
from .models import Client
from .models import CsgoStatData
from .models import CsgoProfileData
from .models import CsgoStats
from .models import PlatformInfo
from .models import Platform
from .info import __version__
from .info import __author__
from .info import __license__
from .info import __copyright__
from .Models import CSGOProfile
from .client import CSGOClient
49 changes: 49 additions & 0 deletions TrackerGG/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2023 DevRuby

MIT License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

"""

import asyncio
import json

from .Models import CSGOProfile
from .httpclient import HTTPClient
from .httpclient import RequestMethod
from .httpclient import ResponseData
from .httpclient import Route


class CSGOClient:
api_key: str
loop: asyncio.AbstractEventLoop
http_client: HTTPClient

def __init__(self, api_key: str) -> None:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
self.loop = asyncio.get_event_loop()
self.api_key = api_key
self.http_client = HTTPClient(self.loop, self.api_key)

async def get_profile(self, identifier: str):
response: ResponseData = await self.http_client.request(
Route(RequestMethod.GET, f"/csgo/standard/profile/steam/{identifier}")
)

assert response.status == 200, "HTTP Response Status Code is not 200"

json_data: dict = json.loads(response.response_data)

return CSGOProfile(json_data["data"])
24 changes: 0 additions & 24 deletions TrackerGG/exceptions.py

This file was deleted.

Loading