From 6c0942898c46823ce1cc8ddcecebb5ad23ea46a1 Mon Sep 17 00:00:00 2001 From: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Date: Wed, 28 Sep 2022 17:18:55 +0200 Subject: [PATCH] Fixes integrated tests for alt and economy (#2655) * Fixes integrated tests for alt and economy * Added fixes * Added fixes --- openbb_terminal/alternative/oss/runa_model.py | 3 ++- openbb_terminal/economy/econdb_model.py | 6 +++++- openbb_terminal/economy/yfinance_model.py | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/openbb_terminal/alternative/oss/runa_model.py b/openbb_terminal/alternative/oss/runa_model.py index 92aa77814e7..94f9ddddc40 100644 --- a/openbb_terminal/alternative/oss/runa_model.py +++ b/openbb_terminal/alternative/oss/runa_model.py @@ -111,7 +111,8 @@ def get_startups() -> pd.DataFrame: pandas.DataFrame: list of startups """ - soup = _make_request("https://runacap.com/ross-index/") + response = requests.get("https://runacap.com/ross-index/", timeout=10) + soup = BeautifulSoup(response.content, "html.parser") startups = [] if soup: table = soup.find("table", {"id": "table_1"}) diff --git a/openbb_terminal/economy/econdb_model.py b/openbb_terminal/economy/econdb_model.py index 775cd22ea04..47fe9c1d12a 100644 --- a/openbb_terminal/economy/econdb_model.py +++ b/openbb_terminal/economy/econdb_model.py @@ -561,7 +561,11 @@ def get_macro_data( return pd.Series(dtype=float), "" if start_date or end_date: - df = df.loc[start_date:end_date] + try: + df = df.loc[start_date:end_date] + except TypeError: + console.print("[red]Invalid date sent. Format as YYYY-MM-DD[/red]\n") + return pd.DataFrame(), "NA/NA" if ( symbol diff --git a/openbb_terminal/economy/yfinance_model.py b/openbb_terminal/economy/yfinance_model.py index ff23376798d..88f1924ac42 100644 --- a/openbb_terminal/economy/yfinance_model.py +++ b/openbb_terminal/economy/yfinance_model.py @@ -2,6 +2,8 @@ __docformat__ = "numpy" import logging +from datetime import datetime +from typing import Optional import pandas as pd import yfinance as yf @@ -590,8 +592,8 @@ INDICES = { def get_index( index: str, interval: str = "1d", - start_date: int = None, - end_date: int = None, + start_date: Optional[str] = None, + end_date: Optional[str] = None, column: str = "Adj Close", ) -> pd.Series: """Obtain data on any index [Source: Yahoo Finance] @@ -600,9 +602,9 @@ def get_index( ---------- index: str The index you wish to collect data for. - start_date : str + start_date : Optional[str] the selected country - end_date : bool + end_date : Optional[str] The currency you wish to convert the data to. interval : str Valid intervals: 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo or 3mo @@ -620,6 +622,15 @@ def get_index( else: ticker = index + try: + if start_date: + datetime.strptime(str(start_date), "%Y-%m-%d") + if end_date: + datetime.strptime(str(end_date), "%Y-%m-%d") + except ValueError: + console.print("[red]Please format date as YYYY-MM-DD[/red]\n") + return pd.Series(dtype="object") + index_data = yf.download( ticker, start=start_date,