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

Feature/companies house #4721

Merged
merged 135 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
846235e
Addition of UK Companies House data. Allows you to search for compani…
kulbinderdio Apr 8, 2023
8b537d0
reformatting of code
kulbinderdio Apr 8, 2023
6ddaea9
reformatting
kulbinderdio Apr 8, 2023
e344f3d
reformat code
kulbinderdio Apr 8, 2023
d0bc697
reformat
kulbinderdio Apr 8, 2023
a7913cb
fix codespell issue
kulbinderdio Apr 8, 2023
164e340
updated for changes in way key are handled
kulbinderdio Apr 8, 2023
7cac122
small reformatting
kulbinderdio Apr 8, 2023
96bb709
added timeout for requests
kulbinderdio Apr 8, 2023
0565a59
formatting
kulbinderdio Apr 8, 2023
30cdc49
ruff order fixes
kulbinderdio Apr 8, 2023
0839d8e
black reformatting
kulbinderdio Apr 8, 2023
1f7bacd
merge issue - removed function call_openbb
kulbinderdio Apr 8, 2023
20f27f7
black format change
kulbinderdio Apr 8, 2023
d6e9c8d
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio Apr 8, 2023
42b7470
Added new Companies House functionality to SDK
kulbinderdio Apr 8, 2023
0652129
Merge branch 'feature/companies_house' of https://github.com/kulbinde…
kulbinderdio Apr 8, 2023
b592e4f
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio Apr 8, 2023
a6be865
formattng
kulbinderdio Apr 8, 2023
7ed8d7e
more Formatting (black)
kulbinderdio Apr 8, 2023
5408994
Ruff fix
kulbinderdio Apr 8, 2023
cfcb17a
change return type for function
kulbinderdio Apr 8, 2023
29993b3
forced type conversion
kulbinderdio Apr 8, 2023
62880b3
return type fix
kulbinderdio Apr 8, 2023
1f9a4b8
correct error return type
kulbinderdio Apr 9, 2023
f68bcf3
fix return type
kulbinderdio Apr 9, 2023
ccfad36
deleted companieshouse tests as they require API key
kulbinderdio Apr 9, 2023
70339bc
Merge branch 'develop' into feature/companies_house
deeleeramone Apr 10, 2023
7c01b79
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio Apr 15, 2023
44749a3
Extra validation added for when data not exist from remote calls
kulbinderdio Apr 15, 2023
4a923ff
Added extra commands to en.yml
kulbinderdio Apr 16, 2023
930e8a8
spelling mistake correction
kulbinderdio Apr 16, 2023
b23dd4b
fat finger trouble corrected
kulbinderdio Apr 16, 2023
500ddc4
Merge branch 'develop' into feature/companies_house
deeleeramone Apr 19, 2023
ee9f763
Save documents with identifying names and allow documents to be viewe…
kulbinderdio Apr 20, 2023
4c6917a
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio Apr 20, 2023
3720d4d
Merge branch 'feature/companies_house' of https://github.com/kulbinde…
kulbinderdio Apr 20, 2023
cfcf19e
ruff updates
kulbinderdio Apr 20, 2023
81b77f8
black changes
kulbinderdio Apr 21, 2023
b763202
ruff change
kulbinderdio Apr 21, 2023
5627da1
Addition of currently loaded company information in menu
kulbinderdio Apr 22, 2023
c474019
Merge branch 'develop' into feature/companies_house
deeleeramone Apr 27, 2023
2af1966
add entry in the API keys guide for Companies Hosue
deeleeramone Apr 27, 2023
25c9bba
adds images to api keys guide
deeleeramone Apr 27, 2023
101a753
adds section in SDK API Keys Guide for Companies House
deeleeramone Apr 27, 2023
d5c52bd
Merge branch 'develop' into feature/companies_house
kulbinderdio Apr 29, 2023
bf7548e
test file for companieshouse_model
kulbinderdio May 8, 2023
d8322ad
changed test data due to ruff line size limit
kulbinderdio May 8, 2023
4740768
Merge branch 'develop' into feature/companies_house
kulbinderdio May 8, 2023
49cffee
resolve merge issues
kulbinderdio May 8, 2023
84d0b33
resolve merge issue
kulbinderdio May 8, 2023
3cb601a
Merge branch 'develop' into feature/companies_house
kulbinderdio May 9, 2023
b8dc214
Merge branch 'develop' into feature/companies_house
kulbinderdio May 9, 2023
7883208
Merge branch 'develop' into feature/companies_house
kulbinderdio May 10, 2023
4a19ffd
Merge branch 'develop' into feature/companies_house
deeleeramone May 11, 2023
0c7d8ee
doc strings examples
deeleeramone May 11, 2023
fc4255a
added docstrings for companieshouse_model
kulbinderdio May 11, 2023
ce02f9a
Merge branch 'develop' into feature/companies_house
deeleeramone May 12, 2023
18a9689
allow download_filking_document methid in view class to be called fro…
kulbinderdio May 14, 2023
52df697
Merge branch 'feature/companies_house' of https://github.com/kulbinde…
kulbinderdio May 14, 2023
f9e6f37
added docstring for download_filing_document SDK method
kulbinderdio May 14, 2023
653972b
Merge branch 'develop' into feature/companies_house
kulbinderdio May 14, 2023
42eeca0
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio May 15, 2023
7997611
Merge branch 'develop' into feature/companies_house
jmaslek May 15, 2023
03a5752
correct Companies house key literal
kulbinderdio May 16, 2023
d57c4cc
Merge branch 'develop' into feature/companies_house
kulbinderdio May 16, 2023
9a33c26
Merge branch 'develop' into feature/companies_house
kulbinderdio May 16, 2023
9013955
Merge branch 'develop' into feature/companies_house
kulbinderdio May 17, 2023
428f6b3
Merge branch 'develop' into feature/companies_house
kulbinderdio May 20, 2023
7553393
Merge branch 'develop' into feature/companies_house
kulbinderdio May 22, 2023
c04d422
Merge branch 'develop' into feature/companies_house
kulbinderdio May 23, 2023
5f454b7
replace starnge . with ,
kulbinderdio May 23, 2023
367982b
Merge branch 'feature/companies_house' of https://github.com/kulbinde…
kulbinderdio May 23, 2023
29c673b
Merge branch 'develop' into feature/companies_house
kulbinderdio May 23, 2023
ec3a5fd
Merge branch 'develop' into feature/companies_house
kulbinderdio May 25, 2023
11c9218
Merge branch 'develop' into feature/companies_house
deeleeramone May 26, 2023
c9a7e57
Merge branch 'develop' into feature/companies_house
kulbinderdio May 28, 2023
7c59b50
add check_api_key decorator to each methopd in controller
kulbinderdio May 28, 2023
b5f29f5
Merge branch 'develop' into feature/companies_house
deeleeramone May 30, 2023
72956f5
Merge branch 'develop' into feature/companies_house
kulbinderdio May 30, 2023
138cfcd
Merge branch 'develop' into feature/companies_house
kulbinderdio May 31, 2023
9ff8735
Merge branch 'develop' into feature/companies_house
deeleeramone May 31, 2023
7a78386
Merge branch 'develop' into feature/companies_house
kulbinderdio Jun 3, 2023
fdb55ba
Merge branch 'develop' into feature/companies_house
deeleeramone Jun 6, 2023
c19c8dd
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio Jun 6, 2023
1c3b143
implement next and previous for looping through filings
kulbinderdio Jun 6, 2023
6b4a137
Merge branch 'feature/companies_house' of https://github.com/kulbinde…
kulbinderdio Jun 6, 2023
1a48867
ruff changes
kulbinderdio Jun 6, 2023
dc82dd7
correct tests
kulbinderdio Jun 7, 2023
1d77fa6
Merge branch 'develop' into feature/companies_house
kulbinderdio Jun 7, 2023
eeb16e2
Merge branch 'develop' into feature/companies_house
kulbinderdio Jun 17, 2023
de4f246
companing filings now allows you specify category
kulbinderdio Jun 17, 2023
a073166
ruff line length issue resolved
kulbinderdio Jun 17, 2023
395e5c2
Merge branch 'develop' into feature/companies_house
kulbinderdio Jun 20, 2023
503e94e
Merge branch 'develop' into feature/companies_house
kulbinderdio Jun 22, 2023
6bd3e8e
Merge branch 'develop' into feature/companies_house
kulbinderdio Jun 24, 2023
cd48112
Merge branch 'develop' into feature/companies_house
kulbinderdio Jul 3, 2023
f46ceb1
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio Jul 11, 2023
c26be38
retrieves all filings and added charges command
kulbinderdio Jul 12, 2023
2abf5b9
bug fix
kulbinderdio Jul 12, 2023
a10964e
Merge branch 'develop' into feature/companies_house
kulbinderdio Jul 13, 2023
1480d97
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio Jul 15, 2023
9abbdf4
Merge branch 'develop' into feature/companies_house
kulbinderdio Jul 19, 2023
c772df4
Added limit parameter to filings command, def :100
kulbinderdio Jul 19, 2023
5d7fe10
Merge branch 'feature/companies_house' of https://github.com/kulbinde…
kulbinderdio Jul 19, 2023
863b129
fix ruff issue
kulbinderdio Jul 19, 2023
e0cf85b
Merge branch 'OpenBB-finance:develop' into feature/companies_house
kulbinderdio Jul 24, 2023
e25b01e
added get_charges to sdk and to test class
kulbinderdio Jul 24, 2023
c1d45d4
resolved ruff line length issue
kulbinderdio Jul 24, 2023
6aa11b1
Merge branch 'develop' into feature/companies_house
kulbinderdio Jul 25, 2023
719ee22
Merge branch 'develop' into feature/companies_house
kulbinderdio Jul 28, 2023
ccea503
Merge branch 'develop' into feature/companies_house
kulbinderdio Jul 30, 2023
7148382
Merge branch 'develop' into feature/companies_house
kulbinderdio Jul 31, 2023
5cc9fc6
Merge branch 'develop' into feature/companies_house
kulbinderdio Aug 3, 2023
e90bf5f
Merge branch 'develop' into feature/companies_house
deeleeramone Aug 8, 2023
4e603c7
Merge branch 'develop' into feature/companies_house
kulbinderdio Aug 9, 2023
9ff1206
add some view tests
deeleeramone Aug 9, 2023
398086c
add some controller tests
deeleeramone Aug 9, 2023
e9d86c2
Merge branch 'develop' into feature/companies_house
deeleeramone Aug 9, 2023
ebb3007
Merge branch 'develop' into feature/companies_house
deeleeramone Aug 9, 2023
a15f223
applying fix not merged to develop yet, column_keep_types=['Company N…
deeleeramone Aug 10, 2023
da05be7
Merge branch 'develop' into feature/companies_house
deeleeramone Aug 10, 2023
3ba87ca
Merge branch 'develop' into feature/companies_house
jmaslek Aug 17, 2023
79827ff
fix i18n description
deeleeramone Aug 17, 2023
19419e4
update test_print_help
deeleeramone Aug 17, 2023
fe5c207
actually update test_print_help.txt
deeleeramone Aug 17, 2023
0393c8d
Update en.yml - no colon
deeleeramone Aug 17, 2023
dd0c17d
Merge branch 'develop' into feature/companies_house
kulbinderdio Aug 23, 2023
48a6b75
rerorder imports - ruff failurre
kulbinderdio Aug 23, 2023
e0d414d
Merge branch 'develop' into feature/companies_house
kulbinderdio Aug 23, 2023
36da776
Merge branch 'develop' into feature/companies_house
kulbinderdio Aug 23, 2023
feabf2d
simple text change
kulbinderdio Aug 24, 2023
0e1989c
Merge branch 'develop' into feature/companies_house
kulbinderdio Aug 26, 2023
c454044
ruff fix
kulbinderdio Aug 26, 2023
64032a6
help text change trying to fix pytest issue
kulbinderdio Aug 27, 2023
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
12 changes: 11 additions & 1 deletion openbb_terminal/alternative/alt_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AlternativeDataController(BaseController):
"""Alternative Controller class"""

CHOICES_COMMANDS: List[str] = ["hn"]
CHOICES_MENUS = ["covid", "oss", "realestate"]
CHOICES_MENUS = ["covid", "oss", "realestate", "companieshouse"]
PATH = "/alternative/"
CHOICES_GENERATION = True

Expand All @@ -41,6 +41,7 @@ def print_help(self):
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")
Expand Down Expand Up @@ -94,3 +95,12 @@ def call_realestate(self, _):
)

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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
"""Companies House Controller."""
__docformat__ = "numpy"

import argparse
import logging
from typing import List, Optional

from openbb_terminal.alternative.companieshouse import companieshouse_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 check_api_key, log_start_end
from openbb_terminal.helper_funcs import (
EXPORT_ONLY_RAW_DATA_ALLOWED,
check_positive,
)
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__)


class CompaniesHouseController(BaseController):

"""Companies House Controller class."""

CHOICES_COMMANDS = [
"search",
"load",
"officers",
"signifcontrol",
"filings",
"filingdocument",
"charges",
]
PATH = "/alternative/companieshouse/"
CHOICES_GENERATION = True

def __init__(self, queue: Optional[List[str]] = None):
"""Construct Data."""
super().__init__(queue)

self.companyNo = ""
self.companyName = ""
self.filingCategory = ""
self.filing_total_count = 0
self.filing_end_index = 0
self.filing_start_index = 0
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"""
company_string = (
f"{self.companyNo} ({self.companyName})" if self.companyNo else ""
)

mt = MenuText("alternative/companieshouse/")
mt.add_param("_company", company_string)
mt.add_raw("\n")
mt.add_cmd("search")
mt.add_cmd("load")
mt.add_cmd("officers")
mt.add_cmd("signifcontrol")
mt.add_cmd("filings")
mt.add_cmd("filingdocument")
mt.add_cmd("charges")

console.print(text=mt.menu_text, menu="UK Companies House Data")

@log_start_end(log=logger)
@check_api_key(["API_COMPANIESHOUSE_KEY"])
def call_search(self, other_args: List[str]):
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="search",
description="Select the company name to search for. [Source: UK Companies House]",
)
parser.add_argument(
"-n",
"--name",
help="name",
type=str.upper,
required="-h" not in other_args,
dest="name",
metavar="name",
nargs="+",
)

parser.add_argument(
"-l",
"--limit",
help="Number of entries to return",
type=check_positive,
required=False,
dest="limit",
metavar="limit",
default=20,
)

if (
other_args
and "-n" not in other_args[0]
and "--name" not in other_args[0]
and "-h" not in other_args
):
other_args.insert(0, "-n")

ns_parser = self.parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
)

if ns_parser:
if ns_parser.name:
query = " ".join(ns_parser.name)
companieshouse_view.display_search(
query, ns_parser.limit, export=ns_parser.export
)
else:
console.print("[red]No entries found for search string[/red]\n")

@log_start_end(log=logger)
@check_api_key(["API_COMPANIESHOUSE_KEY"])
def call_load(self, other_args: List[str]):
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="load",
description="Select the company number to get detailed info on. [Source: UK Companies House]",
)
parser.add_argument(
"-c",
"--companyNo",
help="companyNo",
type=str.upper,
required="-h" not in other_args,
dest="companyNo",
metavar="companyNo",
)

if (
other_args
and "-c" not in other_args[0]
and "--companyNo" not in other_args[0]
and "-h" not in other_args
):
other_args.insert(0, "-c")

ns_parser = self.parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
)

if ns_parser and ns_parser.companyNo:
self.companyNo = ns_parser.companyNo
company = companieshouse_view.display_company_info(
ns_parser.companyNo, export=ns_parser.export
)
if company.dataAvailable():
self.companyName = company.name
self.filing_total_count = 0
self.filing_end_index = 0
console.print(company.name)
console.print(company.address)
console.print(company.lastAccounts)
else:
console.print(
f"[red]No data found for company number {ns_parser.companyNo}[/red]\n"
)

@log_start_end(log=logger)
@check_api_key(["API_COMPANIESHOUSE_KEY"])
def call_officers(self, other_args: List[str]):
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="officers",
description="Select the company number to retrieve officers for. [Source: UK Companies House]",
)

ns_parser = self.parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
)

if self.companyNo:
if ns_parser:
companieshouse_view.display_officers(
self.companyNo, export=ns_parser.export
)
else:
console.print("Must load a company prior to using this command")

@log_start_end(log=logger)
@check_api_key(["API_COMPANIESHOUSE_KEY"])
def call_signifcontrol(self, other_args: List[str]):
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="signifcontrol",
description="Select the company number to retrieve persons with significant control of company. \
[Source: UK Companies House]",
)

ns_parser = self.parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
)

if self.companyNo:
if ns_parser:
companieshouse_view.display_persons_with_significant_control(
self.companyNo, export=ns_parser.export
)
else:
console.print("Must load a company prior to using this command")

@log_start_end(log=logger)
@check_api_key(["API_COMPANIESHOUSE_KEY"])
def call_filings(self, other_args: List[str]):
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="filings",
description="Select the company number to retrieve filling history for. [Source: UK Companies House]",
)

parser.add_argument(
"-k",
"--category",
help="category",
type=str.lower,
required=False,
dest="category",
metavar="category",
choices=[
"accounts",
"address",
"capital",
"incorporation",
"officers",
"resolution",
],
)

parser.add_argument(
"-l",
"--limit",
help="Number of entries to return",
type=check_positive,
required=False,
dest="limit",
metavar="limit",
default=100,
)

ns_parser = self.parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
)

if self.companyNo:
if ns_parser:
category = ns_parser.category if ns_parser.category else ""
self.filingCategory = category
filing_data = companieshouse_view.display_filings(
self.companyNo, category, ns_parser.limit, export=ns_parser.export
)
self.filing_total_count = filing_data.total_count
self.filing_end_index = filing_data.end_index
self.filing_start_index = filing_data.start_index
else:
console.print("Must load a company prior to using this command")

@log_start_end(log=logger)
@check_api_key(["API_COMPANIESHOUSE_KEY"])
def call_filingdocument(self, other_args: List[str]):
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="filingdocument",
description="Select the company number and transaction ID to retrieve filling history for. \
[Source: UK Companies House]",
)

parser.add_argument(
"-t",
"--transactionID",
help="transactionID",
action="store",
required=("-h" not in other_args),
dest="transactionID",
metavar="transactionID",
)

if (
other_args
and "-t" not in other_args[0]
and "--transactionID" not in other_args[0]
and "-h" not in other_args
):
other_args.insert(0, "-t")

ns_parser = self.parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
)

if self.companyNo:
if ns_parser:
companieshouse_view.download_filing_document(
self.companyNo,
self.companyName,
ns_parser.transactionID,
export=ns_parser.export,
)
else:
console.print("Must load a company prior to using this command")

@log_start_end(log=logger)
@check_api_key(["API_COMPANIESHOUSE_KEY"])
def call_charges(self, other_args: List[str]):
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="charges",
description="Select the company number to retrieve officers for. [Source: UK Companies House]",
)

ns_parser = self.parse_known_args_and_warn(
parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED
)

if self.companyNo:
if ns_parser:
companieshouse_view.display_charges(
self.companyNo, export=ns_parser.export
)
else:
console.print("Must load a company prior to using this command")
Loading