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

Updated pytrends dependency in config files and remove temp workaround #4989

Merged
merged 4 commits into from
May 9, 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
38 changes: 4 additions & 34 deletions openbb_terminal/common/behavioural_analysis/google_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging

import pandas as pd
import requests
from pytrends.request import TrendReq

from openbb_terminal.decorators import log_start_end
Expand All @@ -28,8 +27,7 @@ def get_mentions(symbol: str) -> pd.DataFrame:
Dataframe of interest over time
"""
try:
# pytrend = TrendReq()
pytrend = _fetch_data()
pytrend = TrendReq()
pytrend.build_payload(kw_list=[symbol])
return pytrend.interest_over_time()

Expand Down Expand Up @@ -58,8 +56,7 @@ def get_regions(symbol: str) -> pd.DataFrame:
"""

try:
# pytrend = TrendReq()
pytrend = _fetch_data()
pytrend = TrendReq()
pytrend.build_payload(kw_list=[symbol])
return pytrend.interest_by_region().sort_values([symbol], ascending=False)

Expand Down Expand Up @@ -89,8 +86,7 @@ def get_queries(symbol: str, limit: int = 10) -> pd.DataFrame:
Dataframe of related queries
"""
try:
# pytrend = TrendReq()
pytrend = _fetch_data()
pytrend = TrendReq()
pytrend.build_payload(kw_list=[symbol])
df = pytrend.related_queries()
df = df[symbol]["top"].head(limit)
Expand Down Expand Up @@ -123,8 +119,7 @@ def get_rise(symbol: str, limit: int = 10) -> pd.DataFrame:
Dataframe containing rising related queries
"""
try:
# pytrend = TrendReq()
pytrend = _fetch_data()
pytrend = TrendReq()
pytrend.build_payload(kw_list=[symbol])
df = pytrend.related_queries()
df = df[symbol]["rising"].head(limit)
Expand All @@ -137,28 +132,3 @@ def get_rise(symbol: str, limit: int = 10) -> pd.DataFrame:
console.print(f"[red]{str(e)}[/red]\n")

return pd.DataFrame()


@log_start_end(log=logger)
def _fetch_data() -> TrendReq:
"""Fetch data from pytrends api. [Source: google trends].

Creates a requests session and fetches the cookie from the
google trends website. This cookie is then used to create a
TrendReq object.

Returns
-------
TrendReq
TrendReq object
"""
session = requests.Session()
session.get("https://trends.google.com")
cookies_map = session.cookies.get_dict()
nid_cookie = cookies_map["NID"]
return TrendReq(
hl="en-US",
tz=360,
retries=3,
requests_args={"headers": {"Cookie": f"NID={nid_cookie}"}},
)
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ yfinance = "^0.2.12"
pmaw = "^3.0.0"
praw = "^7.1.4"
Quandl = "^3.6.0"
pytrends = "^4.9.1"
pytrends = "4.9.2"
matplotlib = "^3.3.3"
plotly = "^5.0.0"
prompt-toolkit = "^3.0.16"
Expand Down
2 changes: 1 addition & 1 deletion requirements-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ python-dateutil==2.8.2 ; python_version >= "3.8" and python_full_version != "3.9
python-dotenv==0.19.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
python-i18n==0.3.9 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytorch-lightning==1.6.5 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytrends==4.9.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytrends==4.9.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytz-deprecation-shim==0.1.0.post0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytz==2022.7.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pywin32-ctypes==0.2.0 ; python_version >= "3.8" and python_version < "3.11" and python_full_version != "3.9.7" and sys_platform == "win32"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ python-coinmarketcap==0.2 ; python_version >= "3.8" and python_full_version != "
python-dateutil==2.8.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
python-dotenv==0.19.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
python-i18n==0.3.9 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytrends==4.9.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytrends==4.9.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytz-deprecation-shim==0.1.0.post0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pytz==2022.7.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
pywin32==305 ; sys_platform == "win32" and platform_python_implementation != "PyPy" and python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
Expand Down