Files
OpenBB/openbb_terminal/alternative/alt_controller.py
dio db9d462188 Feature/companies house (#4721)
* Addition of UK Companies House data. Allows you to search for companies and inspect their details and download any filings including accounts

* reformatting of code

* reformatting

* reformat code

* reformat

* fix codespell issue

* updated for changes in way key are handled

* small reformatting

* added timeout for requests

* formatting

* ruff order fixes

* black reformatting

* merge issue - removed function call_openbb

* black format change

* Added new Companies House functionality to SDK

* formattng

* more Formatting (black)

* Ruff fix

* change return type for function

* forced type conversion

* return type fix

* correct error return type

* fix return type

* deleted companieshouse tests as they require API key

* Extra validation added for when data not exist from remote calls

* Added extra commands to en.yml

* spelling mistake correction

* fat finger trouble corrected

* Save documents with identifying names and allow documents to be viewed directly within OpenBB

* ruff updates

* black changes

* ruff change

* Addition of currently loaded company information in menu

* add entry in the API keys guide for Companies Hosue

* adds images to api keys guide

* adds section in SDK API Keys Guide for Companies House

* test file for companieshouse_model

* changed test data due to ruff line size limit

* resolve merge issues

* resolve merge issue

* doc strings examples

* added docstrings for companieshouse_model

* allow download_filking_document methid in view class to be called from SDK

* added docstring for download_filing_document SDK method

* correct Companies house key literal

* replace starnge . with ,

* add check_api_key decorator to each methopd in controller

* implement next and previous for looping through filings

* ruff changes

* correct tests

* companing filings now allows you specify category

* ruff line length issue resolved

* retrieves all filings  and  added charges command

* bug fix

* Added limit parameter to filings command, def :100

* fix ruff issue

* added get_charges to sdk and to test class

* resolved ruff line length issue

* add some view tests

* add some controller tests

* applying fix not merged to develop yet, column_keep_types=['Company Number']

* fix i18n description

* update test_print_help

* actually update test_print_help.txt

* Update en.yml - no colon

* rerorder imports - ruff failurre

* simple text change

* ruff fix

* help text change trying to fix pytest issue

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>
2023-08-28 14:28:33 +00:00

107 lines
3.4 KiB
Python

"""Alternative Data Controller Module"""
__docformat__ = "numpy"
import argparse
import logging
from typing import List, Optional
from openbb_terminal.alternative import hackernews_view
from openbb_terminal.core.session.current_user import get_current_user
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import EXPORT_ONLY_RAW_DATA_ALLOWED
from openbb_terminal.menu import session
from openbb_terminal.parent_classes import BaseController
from openbb_terminal.rich_config import MenuText, console
logger = logging.getLogger(__name__)
# pylint:disable=import-outside-toplevel
class AlternativeDataController(BaseController):
"""Alternative Controller class"""
CHOICES_COMMANDS: List[str] = ["hn"]
CHOICES_MENUS = ["covid", "oss", "realestate", "companieshouse"]
PATH = "/alternative/"
CHOICES_GENERATION = True
def __init__(self, queue: Optional[List[str]] = None):
"""Constructor"""
super().__init__(queue)
if session and get_current_user().preferences.USE_PROMPT_TOOLKIT:
choices: dict = self.choices_default
self.completer = NestedCompleter.from_nested_dict(choices)
def print_help(self):
"""Print help"""
mt = MenuText("alternative/")
mt.add_menu("covid")
mt.add_menu("oss")
mt.add_menu("realestate")
mt.add_menu("companieshouse")
mt.add_raw("\n")
mt.add_cmd("hn")
console.print(text=mt.menu_text, menu="Alternative")
@log_start_end(log=logger)
def call_covid(self, _):
"""Process covid command"""
from openbb_terminal.alternative.covid.covid_controller import CovidController
self.queue = self.load_class(CovidController, self.queue)
@log_start_end(log=logger)
def call_oss(self, _):
"""Process oss command."""
from openbb_terminal.alternative.oss.oss_controller import OSSController
self.queue = self.load_class(OSSController, self.queue)
@log_start_end(log=logger)
def call_hn(self, other_args: List[str]):
"""Process hn command."""
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="hn",
description="Display Hacker News",
)
ns_parser = self.parse_known_args_and_warn(
parser,
other_args,
export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED,
limit=10,
)
if ns_parser:
hackernews_view.display_stories(
limit=ns_parser.limit,
export=ns_parser.export,
sheet_name=" ".join(ns_parser.sheet_name)
if ns_parser.sheet_name
else None,
)
@log_start_end(log=logger)
def call_realestate(self, _):
"""Process realestate command."""
from openbb_terminal.alternative.realestate.realestate_controller import (
RealEstateController,
)
self.queue = self.load_class(RealEstateController, self.queue)
@log_start_end(log=logger)
def call_companieshouse(self, _):
"""Process companieshouse command."""
from openbb_terminal.alternative.companieshouse.companieshouse_controller import (
CompaniesHouseController,
)
self.queue = self.load_class(CompaniesHouseController, self.queue)