You've already forked KemoFureApi
KF3: Api additions and improvements.
This commit is contained in:
28
endpoints/KF3/friend.py
Normal file
28
endpoints/KF3/friend.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from flask_restful import Resource
|
||||
from flask import current_app as app
|
||||
from flask import request
|
||||
import json
|
||||
|
||||
class KF3_Friend(Resource):
|
||||
def get(self, id:int):
|
||||
db = app.databases["KF3"]
|
||||
if "wiki" in request.args:
|
||||
result = db.get_chara_wiki(id)
|
||||
|
||||
response = app.response_class(
|
||||
response=result,
|
||||
status=200,
|
||||
mimetype='text/plain'
|
||||
)
|
||||
else:
|
||||
result = db.get_chara(id)
|
||||
result = json.dumps(result, ensure_ascii=False, indent=1)
|
||||
|
||||
response = app.response_class(
|
||||
response=result,
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
26
endpoints/KF3/friends.py
Normal file
26
endpoints/KF3/friends.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import json
|
||||
from flask_restful import Resource
|
||||
from flask import current_app as app
|
||||
from flask import request
|
||||
|
||||
class KF3_Friends(Resource):
|
||||
def get(self):
|
||||
db = app.databases["KF3"]
|
||||
result = []
|
||||
for value in db.processed_friends.values():
|
||||
result.append({"id": value["id"], "name": value["nameEn"], "startTime" : value["startTime"], "startTimeRaw" : value["startTimeRaw"]})
|
||||
|
||||
sort_arg = request.args["sort"] if "sort" in request.args and request.args["sort"] in result[0] else "id"
|
||||
if sort_arg == "startTime":
|
||||
sort_arg = "startTimeRaw"
|
||||
|
||||
result = sorted(result, key=lambda f: f[sort_arg])
|
||||
|
||||
response = app.response_class(
|
||||
response=json.dumps(result, ensure_ascii=False, indent=1),
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
|
||||
return response
|
||||
27
endpoints/KF3/update.py
Normal file
27
endpoints/KF3/update.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from flask_restful import Resource
|
||||
from flask import current_app as app
|
||||
from flask import request
|
||||
import json
|
||||
|
||||
class KF3_Update(Resource):
|
||||
def post(self):
|
||||
db = app.databases["KF3"]
|
||||
try:
|
||||
db.reload_data()
|
||||
response = app.response_class(
|
||||
response="update successful",
|
||||
status=200,
|
||||
mimetype='text/plain'
|
||||
)
|
||||
except:
|
||||
response = app.response_class(
|
||||
response="update failed",
|
||||
status=500,
|
||||
mimetype='text/plain'
|
||||
)
|
||||
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
|
||||
def get(self):
|
||||
return self.post()
|
||||
25
endpoints/Kingdom/friend.py
Normal file
25
endpoints/Kingdom/friend.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from flask_restful import Resource
|
||||
from flask import current_app as app
|
||||
from flask import request
|
||||
|
||||
class Kingdom_Friend(Resource):
|
||||
def get(self, id:int):
|
||||
if "wiki" in request.args:
|
||||
result = app.databases["Kingdom"].get_chara_wiki(id)
|
||||
|
||||
response = app.response_class(
|
||||
response=result,
|
||||
status=200,
|
||||
mimetype='text/plain'
|
||||
)
|
||||
else:
|
||||
result = app.databases["Kingdom"].get_chara(id)
|
||||
|
||||
response = app.response_class(
|
||||
response=result,
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
21
endpoints/Kingdom/friends.py
Normal file
21
endpoints/Kingdom/friends.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import json
|
||||
from flask_restful import Resource
|
||||
from flask import current_app as app, jsonify
|
||||
|
||||
class Kingdom_Friends(Resource):
|
||||
def get(self):
|
||||
db = app.databases["Kingdom"]
|
||||
result = []
|
||||
for value in db.processed_friends.values():
|
||||
result.append({"id": value["sn"], "name": value["name"], "describe": value["describe"]["content"] if "content" in value["describe"] else ""})
|
||||
|
||||
result = sorted(result, key=lambda f: f["id"])
|
||||
|
||||
response = app.response_class(
|
||||
response=json.dumps(result, ensure_ascii=False, indent=1),
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
|
||||
return response
|
||||
16
endpoints/Kingdom/item.py
Normal file
16
endpoints/Kingdom/item.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from flask_restful import Resource
|
||||
from flask import current_app as app
|
||||
from flask import request
|
||||
|
||||
class Kingdom_Item(Resource):
|
||||
def get(self, id:int):
|
||||
result = app.databases["Kingdom"].get_item(id)
|
||||
|
||||
response = app.response_class(
|
||||
response=result,
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
23
endpoints/Kingdom/items.py
Normal file
23
endpoints/Kingdom/items.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import json
|
||||
from flask_restful import Resource
|
||||
from flask import current_app as app, jsonify
|
||||
|
||||
class Kingdom_Items(Resource):
|
||||
def get(self):
|
||||
db = app.databases["Kingdom"]
|
||||
result = []
|
||||
for key in db.kfk_en_item.indexed_data.keys():
|
||||
new_value = db.kfk_en_item.indexed_data[key]
|
||||
new_value["id"] = key
|
||||
result.append(new_value)
|
||||
|
||||
result = sorted(result, key=lambda f: f["id"])
|
||||
|
||||
response = app.response_class(
|
||||
response=json.dumps(result, ensure_ascii=False, indent=1),
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
|
||||
return response
|
||||
Reference in New Issue
Block a user