How to use the mcstatus.McServer function in mcstatus

To help you get started, we’ve selected a few mcstatus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thechunknetwork / mc-status-viewer / app / app.py View on Github external
json_response = None

with open('config.yml', 'r') as cfg_file:
    servers_config = yaml.load(cfg_file)

# c = 0.0

for category in servers_config:
    print category
    data[category] = {}
    for server in servers_config[category]:
        print "- " + server + ": " + servers_config[category][server]
        ip = servers_config[category][server]
        if "/" not in ip:
            ip += "/25565"
        status = mcstatus.McServer(ip.split("/")[0], ip.split("/")[1])
        # c += 1
        data[category][server] = status

def update_all():
#    i = 0.0
    for category in data:
#        d = 5.0 / c
        for server in data[category]:
#            i += 1.0
            status = data[category][server]
            threading.Thread(target=lambda: status.Update()).start()
            
def sort_dict_by_key(to_sort):
    return OrderedDict(sorted(to_sort.items(), key=lambda t: t[0]))

def generate_json():
github vemacs / cloudflare-autorotate / updaterecords.py View on Github external
def get_slp_results(ips):
    results = {}
    for ip in ips:
        status = mcstatus.McServer(ip, '25565')
        status.Update()
        results[ip] = status.available
    return results
github vemacs / cloudflare-autorotate / mcstatus.py View on Github external
level=logging.DEBUG)

  summary_line, _, main_doc = __doc__.partition('\n\n')
  parser = argparse.ArgumentParser(
      description=summary_line,
      epilog=main_doc,
      formatter_class=argparse.RawDescriptionHelpFormatter)
  parser.add_argument(
      '--port', type=int, default=DEFAULT_PORT,
      help='defaults to %d' % DEFAULT_PORT)
  parser.add_argument('host')
  args = parser.parse_args()

  logging.info('querying %s:%d', args.host, args.port)

  server = McServer(args.host, port=args.port)
  server.Update()
  if server.available:
    logging.info(
        'available, %d/%d online: %s',
        server.num_players_online, server.max_players_online,
        ', '.join(server.player_names_sample))
  else:
    logging.info('unavailable')