Documentation

The KBGetter module is used to perform all actions related to downloading, storing and creating articles on the local machine.

class KBgetter.FSGetter(username, password, kb_url, kb_path='', kb_name='KB')

Bases: object

Creates the local file structure and database, uses the FreshService 2.0 API to retrieve data and store it in the database and individual files, creates local versoins of the articles and downloads the associated images.

Parameters:
  • username (str, required.) – User name for login to FreshService API(2.0).

  • password (str, required.) – Password for login to Freshservice API(2.0). When using an API key the password will be “X”.

  • kb_url (str, required.) – The URL for the instance of the FreshService API.

  • kb_path (str, optional (default = '').) – The path to the local folder where the knowledgebase will be created. If not set this varialbe will need to be set and make_directories called to create the directory structure for the local knowledgebase.

  • kb_name (str, optional (default = 'KB').) – The name of the folder to be created where the local knowledgebase will be created.

article_to_html(article, folders, categories)

Create html for articles retrieved from the database, remove invalid characters, and clean them using BeautifulSoup

Parameters:
  • article (str, required) – The article from the folder_articles table.

  • folders (list, required) – The folder where the article is stored in FreshService.

  • categories (list, required) – The category where the folder for the article is stored in FreshService.

Returns:

html for the article

Return type:

str

build_kb()

Create the database and build and populate the categories, folders, and folder_articles tables.

Returns:

A list of the dicts for categories and folders, and the count of folder_articles.

Return type:

list

get_categories(db)

Creates the categories table, retrieves the categories from FreshService, and populates the categories table in the database.

Parameters:

db (TinyDB instance, required.) – The TinyDB database created for the knowledgebase.

Returns:

Categories contained in the insntance of FreshService Solutions.

Return type:

dict

get_folder_articles(folders, db)

Creates the folder_articles table, retrieves the articles from each folder from FreshService, and populates the folder_articles table in the database. The articles retrieved from FreshService folders are contained in a single json file, converted into a dict, then stored in the local database.

Parameters:
  • folders (dict, required.) – The folders from the specified instance of FreshService Solutions.

  • db (TinyDB instance, required.) – The TinyDB database created for the knowledgebase.

Returns:

The count of folder articles inserted into the folder_articles table.

Return type:

int

get_folders(categories, db)

Creates the folders table, retrieves the folders from FreshService, and populates the folders table in the database.

Parameters:
  • categories (dict, required.) – The categories from the specified instance of FreshService Solutions.

  • db (TinyDB instance, required.) – The TinyDB database created for the knowledgebase.

Returns:

Folders contained in the insntance of FreshService Solutions.

Return type:

dict

make_articles(current_categories=[])

Get individual articles from the database based on the provided categories, pass them to article_to_html, and write the html code to the local articles folder.

Parameters:

current_categories (list, optional (if blank retrieve articles from all categories).) – The list of category IDs from which the local html articles will be created. The articles created will retain all information from FreshService including href and img src locations. If no list is passed the function will retrieve articles from all categories. If a list of categories is provided only articles from the categories provided will be created.

Returns:

The total number of articles created.

Return type:

int

make_directories()

Creates the local file struture for the knowledgebase. Sets the local paths for where the files will be stored.

make_local_articles()

Create articles for the local knowledgebase from the articles folder and download the article images. This replaces all the FreshService hrefs and img srcs with a relative path to the local files.

Returns:

The total number of articles created.

Return type:

int