From 8c24a11bf86eb4ad4f25c74476b040636c49728b Mon Sep 17 00:00:00 2001 From: wleong1 Date: Thu, 7 Mar 2024 00:41:07 +0000 Subject: [PATCH] Added timeout for requests --- .github/workflows/ci.yml | 3 +-- src/live_price_display.py | 3 ++- src/news_display.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b822884..3bf5d75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,6 @@ jobs: - name: Install Dependencies run: | pip install mypy - mypy src --install-types - name: mypy run: | mypy src/ @@ -71,7 +70,7 @@ jobs: python-version: 3.x - name: Install Dependencies run: | - pip install pytest requests pandas + pip install pytest requests pandas yfinance - name: pytest run: | pytest tests/ \ No newline at end of file diff --git a/src/live_price_display.py b/src/live_price_display.py index ec37348..b14b4af 100644 --- a/src/live_price_display.py +++ b/src/live_price_display.py @@ -34,7 +34,8 @@ def display_final_price_av(company_name: str) -> Union[str, dict, Any]: "symbol": company_name, } price_response: requests.models.Response = requests.get( - ALPHA_VANTAGE_ENDPOINT, params=price_params + ALPHA_VANTAGE_ENDPOINT, params=price_params, + timeout=20 ) if price_response.ok: response_data: dict = price_response.json() diff --git a/src/news_display.py b/src/news_display.py index bbc65e8..0668712 100644 --- a/src/news_display.py +++ b/src/news_display.py @@ -25,7 +25,8 @@ def _collect_news(company_name: str) -> list: news_params: dict = {"apiKey": NEWS_API_KEY, "qInTitle": company_name} news_response: requests.models.Response = requests.get( - NEWS_ENDPOINT, params=news_params + NEWS_ENDPOINT, params=news_params, + timeout=20 ) articles: list = news_response.json()["articles"] five_articles: list = articles[:5]