Skip to content

Instantly share code, notes, and snippets.

@vemacs
Created August 20, 2014 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vemacs/b5828e294ff1c1d23907 to your computer and use it in GitHub Desktop.
Save vemacs/b5828e294ff1c1d23907 to your computer and use it in GitHub Desktop.
import mcstatus, time, threading
from bottle import route, run, response, hook
server = mcstatus.McServer('hub.thechunk.net', 25565)
def schedule_update():
threading.Timer(1, schedule_update).start()
threading.Thread(target=lambda: server.Update()).start()
@hook('after_request')
def enable_cors():
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'PUT, GET, POST, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
@route('/count')
def index():
count = server.num_players_online
if server.available:
return str(count) + ' <b>Playing Now</b>'
else:
return '<i>Offline</i>, Back Soon!'
schedule_update()
try:
run(host='localhost', port=8082)
except KeyboardInterrupt:
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment