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

Refactor requests throughout #4033

Merged
merged 16 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_most_shorted() -> pd.DataFrame:
url = "https://finance.yahoo.com/screener/predefined/most_shorted_stocks"

data = pd.read_html(
requests.get(url, headers={"User-Agent": get_user_agent()}).text
request(url, headers={"User-Agent": get_user_agent()}).text
)[0]
data = data.iloc[:, :-1]
return data
Expand Down Expand Up @@ -137,7 +137,7 @@ def get_economy_calendar_events() -> pd.DataFrame:
pd.DataFrame
Get dataframe with economic calendar events
"""
response = requests.get(
response = request(
f"https://finnhub.io/api/v1/calendar/economic?token={cfg.API_FINNHUB_KEY}"
)

Expand Down
7 changes: 3 additions & 4 deletions openbb_terminal/alternative/hackernews_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import logging
import pandas as pd
import requests

from openbb_terminal.helper_funcs import request
from openbb_terminal.decorators import log_start_end

logger = logging.getLogger(__name__)
Expand All @@ -24,12 +23,12 @@ def get_stories(limit: int = 10) -> pd.DataFrame:
DataFrame with stories
"""

res = requests.get("https://hacker-news.firebaseio.com/v0/topstories.json")
res = request("https://hacker-news.firebaseio.com/v0/topstories.json")
if res.status_code == 200:
top_stories = res.json()
stories = []
for story_id in top_stories[:limit]:
story = requests.get(
story = request(
f"https://hacker-news.firebaseio.com/v0/item/{story_id}.json"
).json()
stories.append(story)
Expand Down
5 changes: 2 additions & 3 deletions openbb_terminal/alternative/oss/github_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
from typing import Any, Dict, Optional
import math
from datetime import datetime
import requests
import pandas as pd

from openbb_terminal import config_terminal as cfg
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.rich_config import console
from openbb_terminal.helper_funcs import get_user_agent
from openbb_terminal.helper_funcs import get_user_agent, request

logger = logging.getLogger(__name__)

Expand All @@ -33,7 +32,7 @@ def get_github_data(url: str, **kwargs) -> Optional[Dict[str, Any]]:
Dict[str, Any]
Dictionary with data
"""
res = requests.get(
res = request(
url,
headers={
"Authorization": f"token {cfg.API_GITHUB_KEY}",
Expand Down
6 changes: 3 additions & 3 deletions openbb_terminal/alternative/oss/runa_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from urllib3.util.retry import Retry

from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import get_user_agent
from openbb_terminal.helper_funcs import get_user_agent, request
from openbb_terminal.rich_config import console

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -80,7 +80,7 @@ def _make_request(url: str) -> Union[BeautifulSoup, None]:
headers = {"User-Agent": get_user_agent()}
session = _retry_session("https://runacap.com/")
try:
req = session.get(url, headers=headers, timeout=5)
req = session.get(url, headers=headers)
except Exception as error:
logger.exception(str(error))
console.print(error)
Expand Down Expand Up @@ -109,7 +109,7 @@ def get_startups() -> pd.DataFrame:
pd.DataFrame
list of startups
"""
response = requests.get("https://runacap.com/ross-index/", timeout=10)
response = request("https://runacap.com/ross-index/")
soup = BeautifulSoup(response.content, "html.parser")
startups = []
if soup:
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/common/behavioural_analysis/finbrain_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

import pandas as pd
import requests
from openbb_terminal.helper_funcs import request

from openbb_terminal.decorators import log_start_end

Expand All @@ -25,7 +25,7 @@ def get_sentiment(symbol: str) -> pd.DataFrame:
pd.DataFrame
Empty if there was an issue with data retrieval
"""
result = requests.get(f"https://api.finbrain.tech/v0/sentiments/{symbol}")
result = request(f"https://api.finbrain.tech/v0/sentiments/{symbol}")
sentiment = pd.DataFrame()
if result.status_code == 200:
result_json = result.json()
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/common/behavioural_analysis/finnhub_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import logging

import pandas as pd
import requests

from openbb_terminal.helper_funcs import request
from openbb_terminal import config_terminal as cfg
from openbb_terminal.decorators import check_api_key, log_start_end
from openbb_terminal.rich_config import console
Expand All @@ -28,7 +28,7 @@ def get_sentiment_stats(ticker: str) -> pd.DataFrame:
pd.DataFrame
Get sentiment stats
"""
response = requests.get(
response = request(
f"https://finnhub.io/api/v1/news-sentiment?symbol={ticker}&token={cfg.API_FINNHUB_KEY}"
)

Expand Down
195 changes: 0 additions & 195 deletions openbb_terminal/common/behavioural_analysis/sentimentinvestor_model.py

This file was deleted.

Loading