Skip to content

Commit

Permalink
Fall back to partial fill-up for current_weather endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemaeyer committed Oct 14, 2024
1 parent 65520a0 commit d31a834
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions brightsky/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,16 @@ def current_weather(
}


def _current_weather(source_ids, not_null=None):
def _current_weather(source_ids, not_null=None, partial=False):
params = {
'source_ids': source_ids,
'source_ids_tuple': tuple(source_ids),
}
where = "source_id IN %(source_ids_tuple)s"
if not_null:
where += ''.join(f" AND {element} IS NOT NULL" for element in not_null)
glue = ' OR ' if partial else ' AND '
extra = glue.join(f"{element} IS NOT NULL" for element in not_null)
where += f'AND ({extra})'
sql = f"""
SELECT *
FROM current_weather
Expand All @@ -174,6 +176,12 @@ def _current_weather(source_ids, not_null=None):
"""
rows = _make_dicts(fetch(sql, params))
if not rows:
if not_null and not partial:
return _current_weather(
source_ids,
not_null=not_null,
partial=True,
)
return {}
return rows[0]

Expand Down

0 comments on commit d31a834

Please sign in to comment.