-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
142 lines (81 loc) · 3.88 KB
/
api.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from flask import *
import json, time, requests
from mcuuid import MCUUID
import re
import os
from mcuuid.tools import is_valid_minecraft_username
from colorama import Fore
from gevent.pywsgi import WSGIServer
from gevent import pywsgi
os.system("cls")
app = Flask(__name__)
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='favicon.ico')
@app.route('/', methods=['GET'])
def home_page():
## <h3>/droptime/(api key)/(player name)</h3>
text = '<h1>Enchanted api</h1>\n<h2>welcome user to the enchanted api!\navalable aliasses : </h2>\n<h3>/player/(api key)/(player name)</h3>\n..\n\n<h3>you can get the api key in the disocrd server. go to bot commands and type : e!api key</h3>\n<h2>Disocrd : </h2><a href="https://discord.gg/257AE6wcsG">Join!</a>'
#return text
return text
@app.route('/player/<key>/<user_query>', methods=['GET'])
def player_page(key, user_query):
with open("key.txt", "r") as X:
keys = X.read().lower()
if(str(key) in keys):
#user_query = str(request.args.get('player'))
#user_query = str(user_query)
print(f"getting info on playername {Fore.GREEN}{user_query}{Fore.WHITE}")
if not(user_query):
text2 = "pls enter a name after the ?player="
return text2
player = MCUUID(name=f"{str(user_query)}")
is_good_name = is_valid_minecraft_username(f'{user_query}')
if(is_good_name == False):
data_set = {'valid': f'{is_good_name}'}
json_dump = json.dumps(data_set)
return json_dump
uuid = player.uuid
nameslist = player.names
nameslist = str(nameslist)
nameslist1 = nameslist.replace("{", "").replace("}", "").replace("'", "")
findre = re.search("0: ", nameslist1)
nameslist2 = nameslist1.replace(str(findre), "")
data_set = {'valid': f'{is_good_name}', 'name': f'{user_query}','names': f'{nameslist2}','uuid': f'{uuid}'}
json_dump = json.dumps(data_set)
return json_dump
else:
error = "error"
return error
@app.route('/droptime/<key>/<user_query>', methods=['GET'])
def droptime_page(key, user_query):
with open("key.txt", "r") as X:
keys = X.read().lower()
if(str(key) in keys):
#user_query = str(request.args.get('player'))
#user_query = str(user_query)
print(f"getting info on playername {Fore.GREEN}{user_query}{Fore.WHITE}")
if not(user_query):
text2 = "pls enter a name after the ?player="
return text2
player = MCUUID(name=f"{str(user_query)}")
is_good_name = is_valid_minecraft_username(f'{user_query}')
if(is_good_name == False):
data_set = {'valid': f'{is_good_name}'}
json_dump = json.dumps(data_set)
return json_dump
data = requests.get(f"http://api.coolkidmacho.com/droptime/wow").json()
data = data['UNIX']
data_set = {'valid': f'{is_good_name}', 'name': f'{user_query}','Droptime': f'{data}'}
json_dump = json.dumps(data_set)
return json_dump
@app.route('/info', methods=['GET'])
def info_page():
return redirect("https://pastebin.com/raw/uG5PnGUt", code=302)
if __name__ == '__main__':
# 192.168.2.16
# 192.168.2.2
server = pywsgi.WSGIServer(('192.168.2.2', 80), app)
server.serve_forever()
#app.run(host='0.0.0.0', port=80)