Skip to content

Commit

Permalink
feat: add blocked servers (#26)
Browse files Browse the repository at this point in the history
* chore: added url for get_blocked_servers function

* feat: added get_blocked_servers function

* test: added tests for get_blocked_servers function

* chore: updated README.md

* chore: removed useless condition
  • Loading branch information
Lucino772 authored Feb 10, 2022
1 parent 89c81ad commit 84a381e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Checkout the [documentation](https://pymojang.readthedocs.io/en/latest/)

New features:
- [x] `get_sales`: This function retrieve sales statistics
- [ ] `get_blocked_servers` : This function retrieve blocked server hashes
- [x] `get_blocked_servers` : This function retrieve blocked server hashes
- [ ] `get_username` : This function return the username for a given uuid

The following functions are going to be renamed:
Expand Down
1 change: 1 addition & 0 deletions mojang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_uuids,
get_names,
get_status,
get_blocked_servers,
get_sales,
get_profile,
connect,
Expand Down
1 change: 1 addition & 0 deletions mojang/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .base import (
get_status,
get_sales,
get_blocked_servers,
get_uuid,
get_uuids,
get_names,
Expand Down
8 changes: 8 additions & 0 deletions mojang/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def get_sales(keys: Sequence[str] = None) -> Tuple[int, int, float]:
return (data["total"], data["last24h"], data["saleVelocityPerSeconds"])


def get_blocked_servers() -> List[str]:
"""Get a list of blocked servers hashes"""
response = requests.get(urls.api_get_blocked_servers)
_, data = helpers.err_check(response)

return data.split("\n")


def get_uuid(username: str) -> Optional[str]:
"""Get uuid for a username
Expand Down
1 change: 1 addition & 0 deletions mojang/api/utils/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# URLs for basic api
api_check_status = "https://status.mojang.com/check"
api_get_sales = "https://api.mojang.com/orders/statistics"
api_get_blocked_servers = "https://sessionserver.mojang.com/blockedservers"
api_get_uuid = (
lambda username: f"https://api.mojang.com/users/profiles/minecraft/{username}"
)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_mojang_blocked_servers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import unittest

import mojang


class TestMojangBlockedServers(unittest.TestCase):
def test(self):
self.assertGreater(len(mojang.get_blocked_servers()), 0)

0 comments on commit 84a381e

Please sign in to comment.