You've already forked KemoFureApi
Compare commits
5 Commits
testBranch
...
26a98b53d7
| Author | SHA1 | Date | |
|---|---|---|---|
| 26a98b53d7 | |||
| a36e6940d9 | |||
| 0ce68c606f | |||
| 2b121be258 | |||
| eefb47476a |
4
app.py
4
app.py
@@ -3,7 +3,7 @@ from flask_restful import Api
|
|||||||
|
|
||||||
from modules.KF3.database import Database as KF3DB
|
from modules.KF3.database import Database as KF3DB
|
||||||
from modules.Kingdom.database import Database as KFKDB
|
from modules.Kingdom.database import Database as KFKDB
|
||||||
from modules.JapariSling.database import Database as KFSL
|
from modules.Archive.database import Database as KFADB
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['JSON_AS_ASCII'] = False
|
app.config['JSON_AS_ASCII'] = False
|
||||||
@@ -13,7 +13,7 @@ api = Api(app)
|
|||||||
|
|
||||||
KF3DB(api)
|
KF3DB(api)
|
||||||
KFKDB(api)
|
KFKDB(api)
|
||||||
KFSL(api)
|
KFADB(api)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='127.0.0.1', port=8080, debug=True)
|
app.run(host='127.0.0.1', port=8080, debug=True)
|
||||||
22
modules/Archive/database.py
Normal file
22
modules/Archive/database.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import json
|
||||||
|
from .databaseController import DatabaseController
|
||||||
|
from .endpoints.query import Archive_Query
|
||||||
|
|
||||||
|
class Database:
|
||||||
|
db : DatabaseController = None
|
||||||
|
processed_friends = {}
|
||||||
|
item_stages = {}
|
||||||
|
|
||||||
|
def __init__(self, api) -> None:
|
||||||
|
app = api.app
|
||||||
|
if "Archive" in app.databases:
|
||||||
|
del app.databases["Archive"]
|
||||||
|
|
||||||
|
self.reload_data()
|
||||||
|
|
||||||
|
app.databases["Archive"] = self
|
||||||
|
|
||||||
|
api.add_resource(Archive_Query, "/Archive/Query")
|
||||||
|
|
||||||
|
def reload_data(self):
|
||||||
|
self.db = DatabaseController("/home/pi/python/Katbots/JapariArchive/database.db")
|
||||||
21
modules/Archive/databaseController.py
Normal file
21
modules/Archive/databaseController.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
TABLE_ACCOUNTS = "accounts"
|
||||||
|
TABLE_X = "x_posts"
|
||||||
|
|
||||||
|
class DatabaseController:
|
||||||
|
def __init__(self, db_name):
|
||||||
|
self.conn = sqlite3.connect(db_name, isolation_level="DEFERRED")
|
||||||
|
self.cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
def run_query(self, query):
|
||||||
|
try:
|
||||||
|
self.cursor.execute(query)
|
||||||
|
results = self.cursor.fetchall()
|
||||||
|
return results
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.conn.close()
|
||||||
21
modules/Archive/endpoints/query.py
Normal file
21
modules/Archive/endpoints/query.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import json
|
||||||
|
from flask_restful import Resource
|
||||||
|
from flask import current_app as app, jsonify
|
||||||
|
|
||||||
|
class Archive_Query(Resource):
|
||||||
|
def post(self, query:str):
|
||||||
|
db = app.databases["Archive"]
|
||||||
|
|
||||||
|
result = db.run_query(query)
|
||||||
|
|
||||||
|
if result is None:
|
||||||
|
response = app.response_class(status=400)
|
||||||
|
else:
|
||||||
|
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
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
from typing import List
|
|
||||||
from .construct_serialized import ConstructSerialized
|
|
||||||
|
|
||||||
class ConstructLevel:
|
|
||||||
Name : str
|
|
||||||
Description : str
|
|
||||||
Objects : List[ConstructSerialized]
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
class SVector3:
|
|
||||||
x : float
|
|
||||||
y : float
|
|
||||||
z : float
|
|
||||||
|
|
||||||
class ConstructSerialized:
|
|
||||||
Id : int
|
|
||||||
Variant : int
|
|
||||||
Position : SVector3
|
|
||||||
Rotation : SVector3
|
|
||||||
Width : float
|
|
||||||
Height : float
|
|
||||||
Properties : int
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
|
|
||||||
from .endpoints.get import Get
|
|
||||||
from .endpoints.upload import Upload
|
|
||||||
|
|
||||||
class Database:
|
|
||||||
|
|
||||||
def __init__(self, api) -> None:
|
|
||||||
app = api.app
|
|
||||||
if "JapariSling" in app.databases:
|
|
||||||
del app.databases["JapariSling"]
|
|
||||||
|
|
||||||
app.databases["JapariSling"] = self
|
|
||||||
|
|
||||||
api.add_resource(Upload, "/JapariSling/Upload")
|
|
||||||
api.add_resource(Get, "/JapariSling/Get")
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import os
|
|
||||||
import json
|
|
||||||
from flask_restful import Resource
|
|
||||||
from flask import abort, request, current_app as app
|
|
||||||
|
|
||||||
class Get(Resource):
|
|
||||||
def get(self):
|
|
||||||
dir_name = os.path.join(app.root_path, 'data', 'JapariSling')
|
|
||||||
files = [json.loads(read_file(os.path.join(dir_name, f))) for f in os.listdir(dir_name) if os.path.isfile(os.path.join(dir_name, f))]
|
|
||||||
files = files[:10]
|
|
||||||
files = {"levels": files}
|
|
||||||
|
|
||||||
response = app.response_class(
|
|
||||||
response = json.dumps(files),
|
|
||||||
status=200,
|
|
||||||
mimetype='application/json'
|
|
||||||
)
|
|
||||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
|
||||||
return response
|
|
||||||
|
|
||||||
def read_file(path):
|
|
||||||
with open(path, 'r') as f:
|
|
||||||
return f.read()
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import os
|
|
||||||
import json
|
|
||||||
from flask_restful import Resource
|
|
||||||
from ..classes.construct_level import ConstructLevel
|
|
||||||
from flask import abort, request, current_app as app
|
|
||||||
|
|
||||||
class Upload(Resource):
|
|
||||||
def post(self):
|
|
||||||
cl = request.content_length
|
|
||||||
if cl is not None and cl > 1024:
|
|
||||||
abort(413)
|
|
||||||
|
|
||||||
content = request.json
|
|
||||||
|
|
||||||
if "Name" not in content:
|
|
||||||
abort(400)
|
|
||||||
|
|
||||||
filename = os.path.join(app.root_path, 'data', 'JapariSling', content["Name"] + '.json')
|
|
||||||
|
|
||||||
with open(filename, "wt") as text_file:
|
|
||||||
text_file.write(json.dumps(content, ensure_ascii=False, indent=1))
|
|
||||||
|
|
||||||
response = app.response_class(
|
|
||||||
response="level uploaded",
|
|
||||||
status=200,
|
|
||||||
mimetype='text/plain'
|
|
||||||
)
|
|
||||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
|
||||||
return response
|
|
||||||
Reference in New Issue
Block a user