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

JSON format with "mcstatus [address] json" #74

Closed
wants to merge 4 commits into from
Closed

Conversation

py-mine-bot
Copy link
Collaborator

Klemek Authored by Klemek
Nov 15, 2019
Merged Nov 16, 2019


Following #51 the code was rebased then changed to use json.dumps. Tested successfully on some servers from minecraftservers.org (when ping worked, otherwise it showed {"online": false})

Klemek and others added 4 commits November 15, 2019 14:37
Because JSON format is better for external use.
Need another change to work fine :
in connection.py in classes TCPSocketConnection and UDPSocketConnection :
"def __del__(self):
        try:
            self.socket.close()
        except:
            pass"
Without that there is an unavoidable error printing.

status_res = server.status(retries=1)
data['version'] = status_res.version.name
data['protocol'] = status_res.version.protocol
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kevinkjt2000 Authored by kevinkjt2000
Nov 15, 2019


Outdated (history rewrite) - original diff


@@ -70,6 +71,43 @@ def status():
     )
 
 
+@cli.command(short_help="all available server information in json")
+def json():
+    """
+    Prints server status and query in json. Supported by all Minecraft
+    servers that are version 1.7 or higher.
+    """
+    data = {'online': False}
+    # Build data with responses and quit on exception
+    try:
+        ping_res = server.ping()
+        data['online'] = True
+        data['ping'] = ping_res
+        data = {
+            'online': True,
+            'ping': ping_res,
+        }

I notice that 'online' and 'ping' are repeated above. Please remove lines 86-89, since lines 84-85 already do the same.

@py-mine-bot
Copy link
Collaborator Author

kevinkjt2000 Authored by kevinkjt2000
Nov 16, 2019


Should be released now as version 2.3.0. Thanks again for contributing!

@py-mine-bot py-mine-bot added the Github Import This was auto-imported from upstream repository label Feb 17, 2022
@py-mine-bot py-mine-bot deleted the pr74head branch February 17, 2022 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Github Import This was auto-imported from upstream repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants