Esempio n. 1
0
def asteroid_details(asteroid_slug=None):
  # slug is a slug of asteroid prov des
  if not asteroid_slug:
    return 'Sorry, could not find this asteroid in our database.', 404
  unslug = asteroid_slug.replace('-', ' ')
  candidates = api.autocomplete(unslug, 1)  # TODO better way
  if len(candidates) < 1:
    return 'Sorry, could not find this asteroid in our database.', 404

  asteroid = candidates[0]
  jpl_result = api.jpl_lookup(asteroid['prov_des'])
  if 'spec' in asteroid:
    composition_result = api.compositions()[asteroid['spec']]
  else:
    composition_result = []

  return render_template('asteroid.html', asteroid=asteroid, jpl=jpl_result, composition=composition_result)
Esempio n. 2
0
def asteroid_details(asteroid_slug=None):
  # slug is a slug of asteroid prov des
  if not asteroid_slug:
    return 'Sorry, could not find this asteroid in our database.', 404
  unslug = asteroid_slug.replace('-', ' ')
  # Need to get top 10, otherwise sometimes the best match is not returned by mongo.
  candidates = api.autocomplete(unslug, 10)  # TODO better way?
  if len(candidates) < 1:
    return 'Sorry, could not find this asteroid in our database.', 404

  asteroid = candidates[0]
  jpl_result = api.jpl_lookup(asteroid['prov_des'])
  if 'spec' in asteroid:
    composition_result = api.compositions()[asteroid['spec']]
  else:
    composition_result = []

  return render_template('asteroid.html', asteroid=asteroid, jpl=jpl_result, composition=composition_result)
Esempio n. 3
0
def compositions():
  json_resp = json.dumps(api.compositions())
  return Response(json_resp, mimetype='application/json')