diff --git a/bwresources.py b/bwresources.py index 217dfb6..97d9781 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,9 +202,12 @@ 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): + params = self._fill_mentions_params(kwargs) + return self.project.get(endpoint="data/volume/topics/queries", params=params)["topics"] + def _fill_mentions_params(self, data): if "name" not in data: raise KeyError("Must specify query or group name", data) @@ -218,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]) @@ -230,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: