Skip to content
Open
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
35 changes: 21 additions & 14 deletions src/bcr_api/bwdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def iter_mentions(
"""
params = self._fill_params(name, startDate, kwargs)
page_size = kwargs["pageSize"] if "pageSize" in kwargs else 5000
__delay = kwargs["__delay"] if "__delay" in kwargs else 30
params["pageSize"] = page_size
cursor = params.get("cursor", None)
page_idx = 0
Expand All @@ -77,21 +78,27 @@ def iter_mentions(
break
else:
page_idx += 1
next_cursor, next_mentions = self._get_mentions_page(params)
if len(next_mentions) > 0:
cursor = next_cursor
logger.info(
"Mentions page {} of {} {} retrieved".format(
page_idx, self.resource_type, name
try:
next_cursor, next_mentions = self._get_mentions_page(params)
if len(next_mentions) > 0:
cursor = next_cursor
logger.info(
"Mentions page {} of {} {} retrieved".format(
page_idx, self.resource_type, name
)
)
)
if iter_by_page:
yield next_mentions
else:
for mention in next_mentions:
yield mention
if len(next_mentions) < page_size or not next_cursor:
break
if iter_by_page:
yield next_mentions
else:
for mention in next_mentions:
yield mention
if len(next_mentions) < page_size or not next_cursor:
break
except Exception as e:
if "results" in str(e):
logger.info("Rate limit exceeded, please wait "+str(__delay)+"s ...")
page_idx -= 1
time.sleep(__delay)

def num_mentions(self, name=None, startDate=None, **kwargs):
"""
Expand Down