-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
58 lines (43 loc) · 1.53 KB
/
app.py
File metadata and controls
58 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from flask import Flask, request, jsonify
import json
import server as mcs
import time
from mcstatus import MinecraftServer
import socket
from git import Repo
app = Flask(__name__)
repo = Repo(".")
def simpleHTMLRedirect(url):
return "<html><head><meta http-equiv=\"refresh\" content=\"0; url=" + url + "\"></head></html>"
# This first one is for servers that use TCP to redirect requests by Minecraft to the domain to the server's IP.
@app.route('/mcserver/<server>', methods=['GET'])
def serverTCPNoPort(server):
# creates a server object
server = MinecraftServer.lookup(f"{server}:25565")
serverInfo = mcs.returnMCInfo(server)
if "code" in serverInfo:
code = serverInfo["code"]
else:
code = 200
return jsonify(serverInfo), code
# misc
@app.route("/")
def index():
# Redirects to the website.
return simpleHTMLRedirect("https://byecorps.com/api")
@app.route("/info")
def apiInfo():
# Returns a JSON object with the git commit hash, and date of the commit
# Get the short commit hash
commitShortHash = repo.head.commit.hexsha[:7]
# Get the commit time
commitDate = repo.head.commit.authored_datetime
return jsonify({"verison": f"{commitShortHash}", "committed": f"{commitDate}"})
@app.route("/status/")
def serverStatusRedirect():
return simpleHTMLRedirect("https://status.byecorps.com/")
@app.errorhandler(404)
def page_not_found(e):
return jsonify({"error": "The page you requested was not found.", "code": 404}), 404
if __name__ == '__main__':
app.run()