From d8bc820e1cb8bd008b8742c6ba2072612cf3ed4d Mon Sep 17 00:00:00 2001 From: Jess Bowden Date: Thu, 14 Jul 2016 15:32:28 +0100 Subject: [PATCH 1/3] Added topics endpoints to BWMentionsResource --- bwresources.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bwresources.py b/bwresources.py index 217dfb6..9d05aa3 100644 --- a/bwresources.py +++ b/bwresources.py @@ -205,6 +205,10 @@ def num_mentions(self, **kwargs): params["pageSize"] = 1 return self.project.get(endpoint="data/mentions/count", params=params) + def get_topics(self, **kwargs): + params = self._fill_mentions_params(kwargs) + return self.project.get(endpoint="data/volume/topics/queries", params=params) + def _fill_mentions_params(self, data): if "name" not in data: raise KeyError("Must specify query or group name", data) From e289ce7feb3eeb1020862fd3b2f82581980aba22 Mon Sep 17 00:00:00 2001 From: Paul Siegel Date: Thu, 14 Jul 2016 18:33:54 -0400 Subject: [PATCH 2/3] changed pageSize to page --- bwresources.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bwresources.py b/bwresources.py index 9d05aa3..6566e0c 100644 --- a/bwresources.py +++ b/bwresources.py @@ -174,18 +174,18 @@ def get_mentions(self, max_pages=None, **kwargs): params = self._fill_mentions_params(kwargs) all_mentions = [] - while max_pages == None or params["pageSize"] < max_pages: - next_mentions = self._get_mentions_page(params, params["pageSize"]) + while max_pages == None or params["page"] < max_pages: + next_mentions = self._get_mentions_page(params, params["page"]) if len(next_mentions) > 0: all_mentions += next_mentions if self.console_report: - print("Page " + str(params["pageSize"]) + " of " + self.resource_type + " " + kwargs["name"] + " retrieved") + print("Page " + str(params["page"]) + " of " + self.resource_type + " " + kwargs["name"] + " retrieved") else: break - params["pageSize"] += 1 + params["page"] += 1 if self.console_report: print(str(len(all_mentions)) + " mentions downloaded") @@ -202,7 +202,6 @@ def num_mentions(self, **kwargs): A count of the mentions in a given timeframe. """ params = self._fill_mentions_params(kwargs) - params["pageSize"] = 1 return self.project.get(endpoint="data/mentions/count", params=params) def get_topics(self, **kwargs): @@ -222,7 +221,8 @@ def _fill_mentions_params(self, data): filled["startDate"] = data["startDate"] filled["endDate"] = data["endDate"] if "endDate" in data else ( datetime.date.today() + datetime.timedelta(days=1)).isoformat() - filled["pageSize"] = data["pageSize"] if "pageSize" in data else 1 + filled["pageSize"] = data["pageSize"] if "pageSize" in data else 5000 + filled["page"] = data["page"] if "page" in data else 0 for param in data: setting = self._name_to_id(param, data[param]) @@ -234,7 +234,7 @@ def _fill_mentions_params(self, data): return filled def _get_mentions_page(self, params, page): - params["pageSize"] = page + params["page"] = page mentions = self.project.get(endpoint="data/mentions/fulltext", params=params) if "errors" in mentions: From f44c7b92302b816465ed3d31109e5fc9654b0009 Mon Sep 17 00:00:00 2001 From: Paul Siegel Date: Thu, 14 Jul 2016 18:48:43 -0400 Subject: [PATCH 3/3] return the 'topics' field in BWMentionRequests.get_topics() instead of the whole dictionary --- bwresources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bwresources.py b/bwresources.py index 6566e0c..97d9781 100644 --- a/bwresources.py +++ b/bwresources.py @@ -206,7 +206,7 @@ def num_mentions(self, **kwargs): def get_topics(self, **kwargs): params = self._fill_mentions_params(kwargs) - return self.project.get(endpoint="data/volume/topics/queries", params=params) + return self.project.get(endpoint="data/volume/topics/queries", params=params)["topics"] def _fill_mentions_params(self, data): if "name" not in data: