diff --git a/openbb_terminal/common/behavioural_analysis/google_model.py b/openbb_terminal/common/behavioural_analysis/google_model.py index 0ef4b09e9abe..0abe6294dc0a 100644 --- a/openbb_terminal/common/behavioural_analysis/google_model.py +++ b/openbb_terminal/common/behavioural_analysis/google_model.py @@ -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 @@ -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() @@ -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) @@ -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) @@ -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) @@ -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}"}}, - ) diff --git a/poetry.lock b/poetry.lock index 207b8b957917..9d917f94b3f0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. [[package]] name = "absl-py" @@ -6400,14 +6400,14 @@ test = ["cloudpickle (>=1.3)", "codecov (>=2.1)", "coverage (>=6.4)", "flake8 (> [[package]] name = "pytrends" -version = "4.9.1" +version = "4.9.2" description = "Pseudo API for Google Trends" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "pytrends-4.9.1-py3-none-any.whl", hash = "sha256:fab9dd7f26fe2e6cfff722b7b5fbb093872d0bcb74d860a980f1ae83097e8f52"}, - {file = "pytrends-4.9.1.tar.gz", hash = "sha256:9228055d743b00500b4670c5078c8785436a18d79082b354f7a8e57102ea82d1"}, + {file = "pytrends-4.9.2-py3-none-any.whl", hash = "sha256:d7d0ee956be2f6e3e9fc09376c4615efb9347039d6d1f46e6f4326a5b7a14f67"}, + {file = "pytrends-4.9.2.tar.gz", hash = "sha256:691c6e36b1aeaa4754f3692bdbad0dff446e528ffb052eee2e7f139aaa2c6989"}, ] [package.dependencies] @@ -9692,4 +9692,4 @@ optimization = ["Riskfolio-Lib"] [metadata] lock-version = "2.0" python-versions = "^3.8,<3.11, !=3.9.7" -content-hash = "29f4161609dbefbe373d25a2f561b1a3d37072236e805195150c802e4eb4108f" +content-hash = "ac38f4768093fffb5de6132acb0137b32303ec6157f0de07eb00039e4adf3cb6" diff --git a/pyproject.toml b/pyproject.toml index 89f9e3c92be8..ad7def0e97ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/requirements-full.txt b/requirements-full.txt index 509b2522798b..10da158b7a55 100644 --- a/requirements-full.txt +++ b/requirements-full.txt @@ -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" diff --git a/requirements.txt b/requirements.txt index 51d46cd9938c..01110416d235 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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"