diff --git a/README.md b/README.md index 69ed7042..ec948cf7 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/mojang/__init__.py b/mojang/__init__.py index d0c67a5f..e5d52572 100644 --- a/mojang/__init__.py +++ b/mojang/__init__.py @@ -12,6 +12,7 @@ get_uuids, get_names, get_status, + get_blocked_servers, get_sales, get_profile, connect, diff --git a/mojang/api/__init__.py b/mojang/api/__init__.py index 2c78bd76..bf7b50ec 100644 --- a/mojang/api/__init__.py +++ b/mojang/api/__init__.py @@ -1,6 +1,7 @@ from .base import ( get_status, get_sales, + get_blocked_servers, get_uuid, get_uuids, get_names, diff --git a/mojang/api/base.py b/mojang/api/base.py index 783bd805..eb3f44f6 100644 --- a/mojang/api/base.py +++ b/mojang/api/base.py @@ -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 diff --git a/mojang/api/utils/urls.py b/mojang/api/utils/urls.py index d98f1606..2e0a9969 100644 --- a/mojang/api/utils/urls.py +++ b/mojang/api/utils/urls.py @@ -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}" ) diff --git a/tests/test_mojang_blocked_servers.py b/tests/test_mojang_blocked_servers.py new file mode 100644 index 00000000..29e7e6ed --- /dev/null +++ b/tests/test_mojang_blocked_servers.py @@ -0,0 +1,8 @@ +import unittest + +import mojang + + +class TestMojangBlockedServers(unittest.TestCase): + def test(self): + self.assertGreater(len(mojang.get_blocked_servers()), 0)