-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (47 loc) · 1.57 KB
/
main.py
File metadata and controls
54 lines (47 loc) · 1.57 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
#pip install flask
#pip install sqlalchemy
#pip install mysqlclient
from flask import Flask, json, jsonify
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
#from flask_marshmallow import marshmallow
from marshmallow_sqlalchemy import ModelSchema
from tactic import Category, CategorySchema, Tactic, TacticSchema
from config import SQLALCHEMY_DATABASE_URI
app = Flask(__name__)
engine = create_engine(SQLALCHEMY_DATABASE_URI)
Base = declarative_base()
session = sessionmaker()
session.configure(bind=engine)
s = session()
@app.route("/")
def hello():
#return list of possible calls?
return "nvapi"
@app.route("/categories")
def categories():
#print("# of categories")
#TODO Order by name
allCategories = s.query(Category).all()
#print(len(allCategories))
categorySchema = CategorySchema(many=True)
dump_data = categorySchema.dump(allCategories)
#print(dump_data)
return jsonify(dump_data[0])
@app.route("/category_hierarchy")
def category_hierarchy():
return jsonify("Not Yet Implemented")
#TODO: implement query string search filter arguments
# 1) list of categories
# 2) Whole word search (requires full-text index in db)
#TODO: build adhoc query based on search arguments
@app.route("/tactics")
def tactics():
allTactics = s.query(Tactic).all()
#print(allTactics[0].categories[0].name)
tacticSchema = TacticSchema(many=True)
dump_data = tacticSchema.dump(allTactics)
return jsonify(dump_data[0])
if __name__ == "__main__":
app.run()