FiddleComputers

JSONAPI Minecraft live console (no colors)

Aug 7th, 2019
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import urllib, urllib.parse, urllib.request
  2. import hashlib
  3. import json
  4. import re
  5.  
  6. host = "localhost"
  7. port = 65665
  8. usr = "admin"
  9. pwd = "changeme"
  10. salt = "salt"
  11.  
  12. print("Connecting to "+host+"...")
  13.  
  14. method = "getLatestConsoleLogsWithLimit"
  15. methodToCall = urllib.parse.quote(method)
  16. firstLimit = urllib.parse.quote(json.dumps(['999999']))
  17. limit = urllib.parse.quote(json.dumps(['1']))
  18.  
  19. key = hashlib.sha256()
  20. key.update(usr.encode('utf-8'))
  21. key.update(method.encode('utf-8'))
  22. key.update(pwd.encode('utf-8'))
  23. key.update(salt.encode('utf-8'))
  24.  
  25. key = key.hexdigest()
  26.  
  27. urlAllLogs = "http://{}:{}/api/call?method={}&args={}&key={}".format(host, port, methodToCall, firstLimit, key)
  28.  
  29. f = urllib.request.urlopen(urlAllLogs)
  30. response = json.loads(f.read())
  31.  
  32. last_line = ""
  33.  
  34. if response['result'] == 'success':
  35.     for line in response['success']:
  36.         line['line'] = re.sub(
  37.             r"\[0;[0-9][0-9];[0-9]([0-9]|m)(m|)",
  38.             "",
  39.             line['line']
  40.             )
  41.         line['line'] = re.sub(
  42.             r"\[[0-9][0-9]m((([0-9]|)\[m)|)",
  43.             "",
  44.             line['line']
  45.             )
  46.  
  47.         line['line'] = line['line'].replace("", "")
  48.         line['line'] = line['line'].replace("[m", "")
  49.         print(line['line'], end="")
  50.         last_line = line['line']
  51.  
  52. while True:
  53.     url = "http://{}:{}/api/call?method={}&args={}&key={}".format(host, port, methodToCall, limit, key)
  54.     f = urllib.request.urlopen(url)
  55.     response = json.loads(f.read())
  56.  
  57.     if response['result'] == 'success':
  58.         line = response['success'][0]['line']
  59.         line = re.sub(
  60.             r"\[0;[0-9][0-9];[0-9]([0-9]|m)(m|)",
  61.             "",
  62.             line
  63.             )
  64.         line = re.sub(
  65.             r"\[[0-9][0-9]m((([0-9]|)\[m)|)",
  66.             "",
  67.             line
  68.             )
  69.         line = line.replace("", "")
  70.         line = line.replace("[m", "")
  71.         if not line == last_line:
  72.             last_line = line
  73.             print(line, end="")
RAW Paste Data