Created
August 20, 2014 01:30
-
-
Save vemacs/b5828e294ff1c1d23907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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