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

Count and between 2 dates request case #76

Open
ghost opened this issue May 24, 2021 · 0 comments
Open

Count and between 2 dates request case #76

ghost opened this issue May 24, 2021 · 0 comments

Comments

@ghost
Copy link

ghost commented May 24, 2021

Currently it would seem that in case of a count the elements are randomized. It could be contemplated the case in which you want a list of elements between 2 dates.

Related to #71

Example
https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&start_date=2014-10-01&end_date=2014-10-03&count=2

Response

{"code":400,"msg":"Bad Request: invalid field combination passed. Allowed request fields for apod method are 'concept_tags', 'date', 'hd', 'count', 'start_date', 'end_date', 'thumbs'","service_version":"v1"}

apod-api/application.py

Lines 275 to 276 in d392c15

elif not input_date and not start_date and not end_date and count:
return _get_json_for_random_dates(int(count), use_concept_tags, thumbs)

apod-api/application.py

Lines 150 to 180 in d392c15

def _get_json_for_random_dates(count, use_concept_tags, thumbs):
"""
This returns the JSON data for a set of randomly chosen dates. The number of dates is specified by the count
parameter
:param count:
:param use_concept_tags:
:return:
"""
if count > 100 or count <= 0:
raise ValueError('Count must be positive and cannot exceed 100')
begin_ordinal = datetime(1995, 6, 16).toordinal()
today_ordinal = datetime.today().toordinal()
random_date_ordinals = list(range(begin_ordinal, today_ordinal + 1))
shuffle(random_date_ordinals)
all_data = []
for date_ordinal in random_date_ordinals:
dt = date.fromordinal(date_ordinal)
data = _apod_handler(dt, use_concept_tags, date_ordinal == today_ordinal, thumbs)
# Handle case where no data is available
if not data:
continue
data['service_version'] = SERVICE_VERSION
all_data.append(data)
if len(all_data) >= count:
break
return jsonify(all_data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant