Exemplo n.º 1
0
def horizons():
  query = request.args.get('query')
  result = api.jpl_lookup(query)
  if result:
    json_resp = json.dumps(result)
    return Response(json_resp, mimetype='application/json')
  else:
    return Response('{}', mimetype='application/json')
Exemplo 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('-', ' ')
  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)
Exemplo n.º 3
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)