-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_rich.py
125 lines (98 loc) · 3.64 KB
/
run_rich.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
# encoding: utf-8
# ------------------------------------------------------------------------------
# Name: run_rich.py
# Version: 0.0.7
#
# Summary: Python Fundamentus
# Python Fundamentus is a Python API that allows you to quickly
# access the main fundamental indicators of the main stocks
# in the Brazilian market.
#
# Author: Alexsander Lopes Camargos
# Author-email: alcamargos@vivaldi.net
#
# License: MIT
# ------------------------------------------------------------------------------
"""Fundamentus Command line interface."""
import argparse
from test.textualize import (list_all_companies, list_all_property_funds,
list_all_fundamental_indicators)
from rich import box
from rich.columns import Columns
from rich.console import Console
from rich.panel import Panel
from fundamentus._version import __version__ as version
FOOTER = 'Created by Alexsander Lopes Camargos - ' \
'https://github.com/alexcamargos/pyFundamentus'
def get_arguments() -> argparse.Namespace:
"""Argument parser.
:return: Argument parser.
"""
# Create the parser.
parser = argparse.ArgumentParser(
prog='pyfundamentus',
description='Python Fundamentus is a Python API that allows you to '
'quickly access the main fundamental indicators of the '
'main stocks in the Brazilian market.')
# Add the arguments.
parser.add_argument('-t',
'--ticker',
action='store',
type=str,
help='Stock ticker.')
parser.add_argument('-l',
'--list',
action='store',
type=str,
default='companies',
help='List all companies.')
parser.add_argument('-v',
'--version',
action='version',
version=f'%(prog)s {version}')
return parser.parse_args()
if __name__ == '__main__':
# Get the arguments.
args = get_arguments()
# Initialize the console.
console = Console()
# Clean the console.
console.clear()
if args.ticker:
# Get the panels.
panels = list_all_fundamental_indicators(ticker=args.ticker)
titles = [
'Python Fundamentus', 'Informações Básicas', 'Resumo Financeiro',
'Oscilações', 'Indicadores de Valuation', 'Indicadores de Rentabilidade',
'Indicadores de Endividamento', 'Balanço Patrimonial',
'Demonstrativo de Resultados'
]
# Print the panels.
with console.pager(styles=True) as screen:
for panel, title in zip(panels, titles):
console.print(
Panel(title=title,
renderable=Columns(panel, expand=True),
box=box.HEAVY_EDGE,
expand=True))
# Print the footer.
console.print(FOOTER)
elif args.list == 'companies':
# Get the table.
table = list_all_companies()
# Print the tables.
with console.pager(styles=True) as screen:
console.print('Python Fundamentus')
console.print(table)
# Print the footer.
console.print(FOOTER)
else:
# Get the table.
table = list_all_property_funds()
# Print the tables.
with console.pager(styles=True) as screen:
console.print('Python Fundamentus')
console.print(table)
# Print the footer.
console.print(FOOTER)