Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged List Categories function in to stats function #65

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions kb/actions/list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- encoding: utf-8 -*-
# kb v0.1.3
# A knowledge base organizer
# Copyright © 2020, gnc.
# See /LICENSE for licensing information.

"""
kb list action module

:Copyright: © 2020, alshapton.
:License: GPLv3 (see /LICENSE).
"""

from typing import Dict

import kb.db as db
import kb.initializer as initializer
import kb.filesystem as fs

def list_categories(config: Dict[str, str]):
"""
Returns a list of categories within the knowledge base.

Arguments:

config: - a configuration dictionary containing at least
the following keys:
PATH_KB_DB - the database path of KB
PATH_KB_DATA - the data directory of KB
PATH_KB_HIST - the history menu path of KB
EDITOR - the editor program to call
"""

category_list = dict()
category_list = sorted(fs.list_dirs(config["PATH_KB_DATA"]))
# artifacts = sorted(rows, key=lambda x: x.title)
return category_list
41 changes: 41 additions & 0 deletions kb/api/list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- encoding: utf-8 -*-
# kb v0.1.4
# A knowledge base organizer
# Copyright © 2020, gnc.
# See /LICENSE for licensing information.

"""
kb list api module

:Copyright: © 2020, alshapton.
:License: GPLv3 (see /LICENSE).
"""
import sys
import os
import tarfile
from pathlib import Path
from typing import Dict

from werkzeug.utils import secure_filename

from flask import make_response

from kb.actions.ingest import ingest_kb
from kb.api.constants import MIME_TYPE
import kb.filesystem as fs
import kb.actions.list as ls

def list_cats(config: Dict[str, str]):
"""
List the categories.

Arguments:
config: - a configuration dictionary containing at least
the following keys:
PATH_KB_DATA - the main path of the DATA
"""

categories = ls.list_categories(config)
response = make_response(({'Categories': categories}), 200)
response.mimetype = MIME_TYPE['json']
return response
10 changes: 10 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

# Import the API functions
from kb.api.add import add
from kb.api.list import list_cats
from kb.api.erase import erase
from kb.api.delete import delete, delete_list_of_items_by_ID
from kb.api.export import export
Expand Down Expand Up @@ -178,6 +179,15 @@ def add_item():
resp = add(args=parameters, config=DEFAULT_CONFIG, file=attachment)
return(resp)

@kbapi_app.route('/categories', methods=['GET'])
@auth.login_required
def list_categories():
"""
List all the categories
"""
results = list_cats(config=DEFAULT_CONFIG)
return (results)


@kbapi_app.route('/delete/<int:id>', methods=['POST'])
@auth.login_required
Expand Down