Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove reliance on alerce page return #692

Merged
merged 4 commits into from
Oct 3, 2023
Merged
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
13 changes: 10 additions & 3 deletions tom_alerts/brokers/alerce.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,25 @@ def _clean_parameters(self, parameters):
def _request_alerts(self, parameters):
payload = self._clean_parameters(parameters)
logger.log(msg=f'Fetching alerts from ALeRCE with payload {payload}', level=logging.INFO)
args = urlencode(self._clean_parameters(parameters))
args = urlencode(payload)
response = requests.get(f'{ALERCE_SEARCH_URL}/objects/?count=false&{args}')
response.raise_for_status()
return response.json()

def fetch_alerts(self, parameters):
"""
Loop through pages of ALeRCE alerts until we reach the maximum pages requested.
This simply concatenates all alerts from n pages into a single iterable to be returned.
"""
response = self._request_alerts(parameters)
alerts = response['items']
broker_feedback = ''
if len(alerts) > 0 and response['page'] < parameters.get('max_pages', 1):
parameters['page'] = response.get('page') + 1
current_page = parameters.get('page', 1)
if len(alerts) > 0 and current_page < parameters.get('max_pages', 1):
# make new request for the next page. (by recursion)
parameters['page'] = current_page + 1
alerts += self.fetch_alerts(parameters)[0]
# Bottom out of recursion and return accumulated alerts
return iter(alerts), broker_feedback

def fetch_alert(self, id):
Expand Down
Loading