<jupyter_start><jupyter_text>Track Near Earth Objects ( Asteroids ) Fetching near earth object information using python and NASA NEO API. You can read the api dcumentaton from the link below.url : [NASA NeoWS docs](https://api.nasa.gov/:~:text=NeoWs%20(Near%20Earth%20Object%20Web,browse%20the%20overall%20data%2Dset.)Tutorial for code explanation : [pyGuru Asteroids with python and NeoWS](https://youtu.be/JNL71zQHe3Q) ![not actual image](https://www.gannett-cdn.com/presto/2020/06/04/USAT/a19efbc5-8b9f-4f60-9256-97252d62db75-VPC_ASTEROID_FLY-BY_SAT_wide.jpg?width=660&height=371&fit=crop&format=pjpg&auto=webp)<jupyter_code># importing modules

import requests
from pprint import pprint<jupyter_output><empty_output><jupyter_text>An api key isrequired to access the neo api. Get yourself a api key from here.

url : [Generate api key](https://api.nasa.gov/:~:text=NeoWs%20(Near%20Earth%20Object%20Web,browse%20the%20overall%20data%2Dset)<jupyter_code>api_key = 'your_api_key_here'<jupyter_output><empty_output><jupyter_text>Here, the api gives data for the given range of dates. We will be tracking the asteroids for between 6 and 7 decembers because at this date, asteroid 163348 (2002 NN4), a potentialy hazardous asteroid made a close approach to planet Earth.<jupyter_code># url

start_date = '2020-06-06'
end_date = '2020-06-07'
url = f'https://api.nasa.gov/neo/rest/v1/feed?start_date={start_date}&end_date={end_date}&api_key={api_key}'
url
# making a request and getting data

r = requests.get(url)
data = r.json()
data
total = data['element_count']
neo = data['near_earth_objects']
print('Total asteroids :',total)
neo<jupyter_output>Total asteroids : 21<jupyter_text>If you want to extract all near earth objects information on this day, you can iterate over like this in the dictionary and print everything.<jupyter_code>for near in neo[start_date]:
    print(near['id'], near['name'], near['absolute_magnitude_h'])<jupyter_output>2163348 163348 (2002 NN4) 20.1
2471926 471926 Jormungandr (2013 KN6) 18.6
3398654 (2007 YS56) 25.7
3672459 (2014 KG39) 24.9
54017119 (2020 KO1) 24.93
54017121 (2020 KQ1) 24.161
54017129 (2020 KS1) 21.29
54017329 (2020 LA) 25.221
54017404 (2020 LQ) 25.031
54051325 (2020 QD4) 24.781
54087437 (2020 VV) 27.27
54099646 (2020 XE4) 25.533
54102021 (2020 YP3) 24.132<jupyter_text>You can also extract information of any particular one by passing the correct index<jupyter_code># asteroids by index in the list

first = neo[start_date][0]
first<jupyter_output><empty_output><jupyter_text>Searching About Asteroid : 163348 (2002 NN4)<jupyter_code># finding info by name

all_asteroids = neo[start_date]
for asteroid in all_asteroids:
    if asteroid['name'] == '163348 (2002 NN4)':
        pprint(asteroid)
        break
# asteroid name

asteroid['name']
# asteroid id

asteroid['id']
# nasa url

asteroid['nasa_jpl_url']
# Absolute magnitude : luminosity

asteroid['absolute_magnitude_h']
# diameter

dia = asteroid['estimated_diameter']
dia
# average diameter

avg_dia_m = (dia['meters']['estimated_diameter_min'] + dia['meters']['estimated_diameter_max']) / 2
avg_dia_m
# is potentially hazardous

asteroid['is_potentially_hazardous_asteroid']
# close approach date

close_data = asteroid['close_approach_data']
pprint(close_data)<jupyter_output>[{'close_approach_date': '2020-06-06',
  'close_approach_date_full': '2020-Jun-06 03:20',
  'epoch_date_close_approach': 1591413600000,
  'miss_distance': {'astronomical': '0.0340483556',
                    'kilometers': '5093561.474762572',
                    'lunar': '13.2448103284',
                    'miles': '3164992.3377726136'},
  'orbiting_body': 'Earth',
  'relative_velocity': {'kilometers_per_hour': '40126.2500767766',
                        'kilometers_per_second': '11.1461805769',
                        'miles_per_hour': '24932.8913324282'}}]<jupyter_text>Asteroids making close approachurl : [Earth Close approaches](https://cneos.jpl.nasa.gov/ca/)<jupyter_code>from time import ctime

date = close_data[0]['epoch_date_close_approach']
ctime(date)
# miss distance

miss_distance = close_data[0]['miss_distance']
miss_distance
# relative_velocity

rel_vel = close_data[0]['relative_velocity']
rel_vel
# is sentry object

asteroid['is_sentry_object']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11797621823268828, 'fraction_numerical': 0.11331312660293774, 'mean_word_length': 5.73469387755102, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 6, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '146482', 'license': 'MIT', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1541, 'n_words': 350, 'path': 'Track Near Earth Objects/neoWS.ipynb', 'repo_name': 'pyGuru123/Python-Space-Science', 'size': '4289'}