From fff4cbbd2f0176e818fef22d1aa9a8750ba8f366 Mon Sep 17 00:00:00 2001 From: KIRAN RAJ DHAKAL <65303319+leyuskckiran1510@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:03:07 +0545 Subject: [PATCH 1/3] error handelling for the trending_searches function. To avoid unnecessary Error raise --- pytrends/request.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pytrends/request.py b/pytrends/request.py index dec8b558..3cf3d7e4 100644 --- a/pytrends/request.py +++ b/pytrends/request.py @@ -474,8 +474,11 @@ def trending_searches(self, pn='united_states'): req_json = self._get_data( url=TrendReq.TRENDING_SEARCHES_URL, method=TrendReq.GET_METHOD - )[pn] - result_df = pd.DataFrame(req_json) + ) + keys = req_json.keys() + if(pn not in keys): + return pd.DataFrame(["Data Not Found"]) + result_df = pd.DataFrame(req_json[pn]) return result_df def today_searches(self, pn='US'): From 4d4cbbf1e04ab4c0a215c7a5324b906aecafa860 Mon Sep 17 00:00:00 2001 From: KIRAN RAJ DHAKAL <65303319+leyuskckiran1510@users.noreply.github.com> Date: Mon, 30 Jan 2023 07:43:38 +0000 Subject: [PATCH 2/3] Returning the empty dataFrame insted of the error message data frame. --- pytrends/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytrends/request.py b/pytrends/request.py index 3cf3d7e4..251ccf6d 100644 --- a/pytrends/request.py +++ b/pytrends/request.py @@ -477,7 +477,7 @@ def trending_searches(self, pn='united_states'): ) keys = req_json.keys() if(pn not in keys): - return pd.DataFrame(["Data Not Found"]) + return pd.DataFrame([]) result_df = pd.DataFrame(req_json[pn]) return result_df From ed8c400dd9e0b52d878187802ad01c4f7e1b9a71 Mon Sep 17 00:00:00 2001 From: Eddy Lazzarin <1141361+emlazzarin@users.noreply.github.com> Date: Sat, 8 Apr 2023 00:25:05 -0700 Subject: [PATCH 3/3] hijacks another PR to bump version --- pyproject.toml | 2 +- pytrends/request.py | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 959e743d..6591d60a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pytrends" -version = "4.9.0" +version = "4.9.1" description = "Pseudo API for Google Trends" urls = {homepage = "https://github.com/dreyco676/pytrends"} requires-python = ">=3.7" diff --git a/pytrends/request.py b/pytrends/request.py index 251ccf6d..dec8b558 100644 --- a/pytrends/request.py +++ b/pytrends/request.py @@ -474,11 +474,8 @@ def trending_searches(self, pn='united_states'): req_json = self._get_data( url=TrendReq.TRENDING_SEARCHES_URL, method=TrendReq.GET_METHOD - ) - keys = req_json.keys() - if(pn not in keys): - return pd.DataFrame([]) - result_df = pd.DataFrame(req_json[pn]) + )[pn] + result_df = pd.DataFrame(req_json) return result_df def today_searches(self, pn='US'):