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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
"""Terminal helper"""
__docformat__ = "numpy"
import hashlib
import logging
import os
import subprocess # nosec
import sys
import webbrowser
# IMPORTATION STANDARD
from contextlib import contextmanager
from typing import Any, Dict, List, Optional
import matplotlib.pyplot as plt
# IMPORTATION THIRDPARTY
from packaging import version
# IMPORTATION INTERNAL
import openbb_terminal.core.session.local_model as Local
from openbb_terminal import thought_of_the_day as thought
from openbb_terminal.base_helpers import load_env_files
from openbb_terminal.core.config.paths import HIST_FILE_PATH, SETTINGS_ENV_FILE
from openbb_terminal.core.plots.backend import plots_backend
from openbb_terminal.core.session.constants import BackendEnvironment
from openbb_terminal.core.session.current_system import get_current_system
from openbb_terminal.core.session.current_user import (
get_current_user,
is_local,
set_preference,
)
from openbb_terminal.core.session.env_handler import write_to_dotenv
from openbb_terminal.helper_funcs import request
from openbb_terminal.rich_config import console
# pylint: disable=too-many-statements,no-member,too-many-branches,C0302
try:
__import__("git")
except ImportError:
WITH_GIT = False
else:
WITH_GIT = True
logger = logging.getLogger(__name__)
def print_goodbye():
"""Prints a goodbye message when quitting the terminal"""
# LEGACY GOODBYE MESSAGES - You'll live in our hearts forever.
# "An informed ape, is a strong ape."
# "Remember that stonks only go up."
# "Diamond hands."
# "Apes together strong."
# "This is our way."
# "Keep the spacesuit ape, we haven't reached the moon yet."
# "I am not a cat. I'm an ape."
# "We like the terminal."
# "...when offered a flight to the moon, nobody asks about what seat."
console.print(
"[param]The OpenBB Terminal is the result of a strong community building an "
"investment research platform for everyone, anywhere.[/param]\n"
)
console.print(
"We are always eager to welcome new contributors and you can find our open jobs here:\n"
"[cmds]https://www.openbb.co/company/careers#open-roles[/cmds]\n"
)
console.print(
"Join us : [cmds]https://openbb.co/discord[/cmds]\n"
"Follow us : [cmds]https://openbb.co/twitter[/cmds]\n"
"Ask support : [cmds]https://openbb.co/support[/cmds]\n"
"Request a feature : [cmds]https://openbb.co/request-a-feature[/cmds]\n"
)
console.print(
"[bold]Fill in our 2-minute survey so we better understand how we can improve the OpenBB Terminal "
"at [cmds]https://openbb.co/survey[/cmds][/bold]\n"
)
console.print(
"[param]In the meantime access investment research from your chatting platform using the OpenBB Bot[/param]\n"
"Try it today, for FREE: [cmds]https://openbb.co/products/bot[/cmds]\n"
)
logger.info("END")
def sha256sum(filename):
h = hashlib.sha256()
b = bytearray(128 * 1024)
mv = memoryview(b)
with open(filename, "rb", buffering=0) as f:
for n in iter(lambda: f.readinto(mv), 0):
h.update(mv[:n])
return h.hexdigest()
def update_terminal():
"""Updates the terminal by running git pull in the directory.
Runs poetry install if needed.
"""
if not WITH_GIT or get_current_system().LOGGING_COMMIT_HASH != "REPLACE_ME":
console.print("This feature is not available: Git dependencies not installed.")
return 0
poetry_hash = sha256sum("poetry.lock")
completed_process = subprocess.run( # nosec
"git pull", shell=True, check=False # noqa: S607,S602
)
if completed_process.returncode != 0:
return completed_process.returncode
new_poetry_hash = sha256sum("poetry.lock")
if poetry_hash == new_poetry_hash:
console.print("Great, seems like poetry hasn't been updated!")
return completed_process.returncode
console.print(
"Seems like more modules have been added, grab a coke, this may take a while."
)
completed_process = subprocess.run( # nosec
"poetry install", shell=True, check=False # noqa: S607,S602
)
if completed_process.returncode != 0:
return completed_process.returncode
return 0
def open_openbb_documentation( # noqa: PLR0912
path,
url="https://docs.openbb.co/terminal",
command=None,
arg_type="",
):
"""Opens the documentation page based on your current location within the terminal. Make exceptions for menus
that are considered 'common' by adjusting the path accordingly."""
if path == "/" and command is None:
path = "/usage/overview/structure-and-navigation"
command = ""
elif "keys" in path:
path = "/usage/data/api-keys"
command = ""
elif "settings" in path:
path = "/usage/overview/customizing-the-terminal"
command = ""
elif "featflags" in path:
path = "/usage/overview/customizing-the-terminal#feature-flags-menu"
command = ""
elif "sources" in path:
path = "/usage/usage/data/data-sources"
command = ""
elif "account" in path:
path = "/usage/hub"
command = ""
elif arg_type == "command": # user passed a command name
if command in ["settings", "featflags"]:
path = "/usage/overview/customizing-the-terminal"
command = ""
else:
path = f"/reference/{path}"
elif "askobb" in path:
path = "/usage/askobb-feature"
command = ""
elif arg_type == "menu": # user passed a menu name
if command in ["ta", "qa"]:
menu = path.split("/")[-2]
path = f"/menus/common/{menu}"
elif command == "stocks":
path = "/menus/stocks/introduction"
command = ""
elif command == "forecast":
command = ""
path = "/menus/forecast"
elif command == "crypto":
path = "/menus/crypto/introduction"
command = ""
else:
path = f"/menus/{path}"
else: # user didn't pass argument and is in a menu
menu = path.split("/")[-2]
if menu == "crypto" and not command:
path = "/crypto/introduction"
if menu == "stocks":
path = "/stocks/introduction"
path = f"/menus/common/{menu}" if menu in ["ta", "qa"] else f"/menus/{path}"
if command:
if command == "keys":
path = "/usage/data/api-keys"
command = ""
elif "settings" in path or "featflags" in path:
path = "/usage/overview/customizing-the-terminal"
command = ""
elif "sources" in path:
path = "/usage/data/data-sources"
command = ""
elif command in ["record", "stop", "exe"]:
path = "/usage/routines/introduction-to-routines"
command = ""
elif command == "sources":
path = "/usage/data/data-sources"
command = ""
elif command == "askobb":
path = "/usage/askobb-feature"
command = ""
elif command == "news":
path = "/usage/overview/commands-and-arguments#help-arguments"
command = ""
elif command in [
"intro",
"about",
"support",
"survey",
"update",
"wiki",
]:
path = "/usage"
command = ""
elif command in ["ta", "qa"]:
path = f"/menus/common/{command}"
command = ""
elif command == "stocks":
path = "/menus/stocks/introduction"
command = ""
elif command == "account":
path = "/usage/hub"
command = ""
elif command == "news":
path = "/usage/overview/commands-and-arguments#help-arguments"
command = ""
path += command
full_url = f"{url}{path.replace('//', '/')}"
if full_url[-1] == "/":
|