aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Programming
  • Software Engineering
  • Technology

Build a Python App to Alert You When Asteroids Are Close to Earth

  • aster.cloud
  • May 22, 2023
  • 4 minute read

Being alerted when asteroids are close to Earth is crucial for several reasons:

  1. Planetary Defense: Monitoring and tracking near-Earth asteroids (NEAs) is an essential part of planetary defense. By detecting and characterizing asteroids that come close to our planet, scientists and space agencies can assess potential risks and develop strategies to mitigate or prevent potential impacts.
  2. Early Warning: Alert systems provide early warning about approaching asteroids, allowing scientists to calculate their trajectories and determine whether they pose any threat to Earth. This early warning enables timely decision-making and response planning.
  3. Impact Prediction: Accurate tracking and monitoring of near-Earth asteroids help scientists refine their predictions regarding the future movements and behavior of these objects. By studying their size, composition, and orbital characteristics, researchers can estimate the potential impact consequences and the necessary actions to be taken.
  4. Evacuation and Preparation: In the unlikely event of a significant asteroid posing a threat to Earth, early alerts would provide time for emergency response organizations to plan and execute evacuation procedures in affected areas. This allows communities to be prepared, potentially saving lives and minimizing damage.
  5. Scientific Research: Close encounters with asteroids offer valuable opportunities for scientific research and exploration. By being alerted to their proximity, scientists can coordinate efforts to observe, study, and collect data on these celestial objects, which can enhance our understanding of the solar system’s formation and evolution.
  6. Public Awareness: Publicizing information about close-approaching asteroids raises awareness about the potential risks and the importance of scientific efforts to track and study them. It encourages public engagement, support for research initiatives, and fosters a greater understanding of the Earth’s place in the cosmos.
Read More  How Not To Be A Mediocre Developer!

When you woke up one morning thinking about Armageddon and how fragile we are as a planet if an asteroid comes our way. I am also intrigued by exploring space and the technologies available from my desk. I will show you how to combine two APIs to be alerted via SMS when an asteroid is passing nearby (relatively speaking).


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

NASA OpenAPI

The first resource is NASA’s open API portal. You could use tons of great interfaces for your ideas, but the one that interests me, in this case, is NeoWs (Near Earth Object Web Service).

Unlock

After reading about the API, the first step in your journey is to obtain an API key. This is done by filling your details into a form and providing a valid e-mail.

A screen showing the NASA API registration form

A screen showing the NASA API registration form

Please note that most APIs have an API limit of 1000 requests per hour. They are suitable for tests and personal benefit but not for production-ready usage

Explore

Let’s spend a few minutes to see the data returned by the API to build our use case.

The request (GET)

  • start_date (YYYY-MM-DD) – Starting date for asteroid search
  • end_date (YYYY-MM-DD) – Ending date for asteroid search
  • api_key – the key you received via e-mail after the previous step.

The response

It returns a JSON object with valuable data, which we must work with to get what we need. Look at the data here.

We have a structure called near_earth_objects which contains the details we need in a complex structure:

  • estimated_diameter – the diameter of the asteroid in meters, kilometers, miles, and feet.
  • relative_velocity – the relative velocity of the object
  • miss_distance – the distance away from the orbiting_body
  • orbiting_body – in most cases, is Earth, but you could explore more options if you like.
Read More  Lockheed Martin-Built Orion Spacecraft Is Ready For Its Moon Mission

A screen showing the JSon object received as a response to the request above.

A screen showing the JSon object received as a response to the request above.

Run

So we have all the objects passing nearby and want to get the closest one and alert us daily. Let’s use your Python skills to do that.

#Settings and URL to conect to NASA API
#Get your free API key from here: https://api.nasa.gov/

ad_today = date.today().strftime("%Y-%m-%d")
url = "https://api.nasa.gov/neo/rest/v1/feed?start_date="+ad_today+"&end_date="+ad_today+"&api_key=[your keu]"


#Hadle the responce json
response = requests.request("GET", url)
response.encoding = 'utf-8'
jsn = response.json()


if "near_earth_objects" in jsn:
  

    base = jsn['near_earth_objects'][ad_today]
    i = findClosestEncounter(base)

    #extract the data we need to create the alert
    name = base[i]['name']
    to_appear = base[i]['close_approach_data'][0]['close_approach_date_full']
    how_close = base[i]['close_approach_data'][0]['miss_distance']['kilometers']
    dia_meter =  base[i]['estimated_diameter']['meters']['estimated_diameter_max']


The findClosestEncounter function helps you find the closest object to Earth from the bucket of all things passing nearby. Maybe there is a more elegant solution, but this one works for me well.

def findClosestEncounter(jd):
    # a simple function for discovering the nearest object for the day from all registered objects
    asteroids = []
    for i in range(0, len(jd)):
        asteroids.insert(i,jd[i]['close_approach_data'][0]['miss_distance']['kilometers'])
    return asteroids.index(min(asteroids))

Make it human-readable.

Since we will send an SMS, formatting the data is a good idea. Feel free to use another formatting as well.

 #format the data
    howclose = round(float(how_close))
    diameter = round(dia_meter)

Build the message you want to send via SMS.

#build the message
    alert ="The nearest asteroid for today is "+ name+". It will be "+str(howclose)+" km away with a diameter of "+str(diameter)+" meters."

NeoWs recap

What have you done so far?

  1. You have an API key for the NASA OpenAPI portal
  2. You explored the NeoWs API
  3. You extracted the closest object to Earth from all the objects that could pass nearby.
  4. You crafted a message to alert yourself to this encounter.
Read More  Tiny Snippets Of Code That Changed The World

Let’s send that SMS.

There is another API I want to introduce in this short but helpful example – Messagebird.

Release the bird

Visit their website and register to get an API key

After the registration, you can send a few complimentary SMS messages delivered to your actual phone number. Let’s add this functionality to your Python code.

#SMS client
    #Get your free API key from here: https://developers.messagebird.com/api/#api-endpoint
    sms = messagebird.Client("your API key here")

    #Prepare and send the message to a phone number of your choice.
    # Change the name "Asteroid" to something you want. It will appear as a sender
    message = sms.message_create(
        'Asteroid',
        '+yourphonenumner',
        alert,
        { 'reference' : 'Asteroid' }
    )

Get the Armageddon Alert

You can find the complete script here.

Put all the pieces together and run your code to see whether you did well.  Now you can sleep better, knowing you will be alerted about every big object flying towards the Earth. Of course, NASA needs to detect it first.

If you like the result, you could put it in a cron job and trigger it once a day.

Happy Hacking!

Originally appeared in cyberpogo.com


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

aster.cloud

Related Topics
  • Asteriod
  • Code
  • NASA
  • NEA
  • Predictions
  • Python App
You May Also Like
View Post
  • Technology

IBM and Google Cloud Announce Strategic Partnership to Scale AI with Human Expertise and AI‑Powered Delivery

  • June 4, 2026
View Post
  • Technology

Banks race to patch new cyber vulnerabilities, and other cybersecurity news

  • May 25, 2026
pope-leo-xiv-cq5dam-1500.844
View Post
  • Technology

Pope Leo XIV to Publish First Encyclical on Artificial Intelligence and Human Dignity on 25 May

  • May 22, 2026
View Post
  • Technology

Portfolio to Clients, and is Strengthened by Ongoing Project Glasswing Work

  • May 20, 2026
reMarkable Paper Pure
View Post
  • Gears
  • Technology

Everything The reMarkable Paper Pure Actually Does

  • May 14, 2026
View Post
  • Data
  • Platforms
  • Technology

Scaling cloud and AI: Microsoft Azure’s commitment to Europe’s digital future

  • May 11, 2026
reMarkable Paper Pure
View Post
  • Featured
  • Gears
  • Technology

The Quiet Revolution You Did Not Know You Needed

  • May 9, 2026
View Post
  • Technology

Why The CLOUD Act And Geopolitics Are Forcing A Data Sovereignty Reckoning In Europe

  • May 2, 2026

Stay Connected!
LATEST
  • 1
    IBM and Google Cloud Announce Strategic Partnership to Scale AI with Human Expertise and AI‑Powered Delivery
    • June 4, 2026
  • Data center 2
    Data Sovereignty in Spain. It’s Not Just About the Law, It’s About Efficiency
    • June 3, 2026
  • 3
    Ink vs Pixels. What you miss versus what you are actually missing.
    • June 1, 2026
  • 4
    Banks race to patch new cyber vulnerabilities, and other cybersecurity news
    • May 25, 2026
  • pope-leo-xiv-cq5dam-1500.844 5
    Pope Leo XIV to Publish First Encyclical on Artificial Intelligence and Human Dignity on 25 May
    • May 22, 2026
  • 6
    Portfolio to Clients, and is Strengthened by Ongoing Project Glasswing Work
    • May 20, 2026
  • reMarkable Paper Pure 7
    Everything The reMarkable Paper Pure Actually Does
    • May 14, 2026
  • 8
    Scaling cloud and AI: Microsoft Azure’s commitment to Europe’s digital future
    • May 11, 2026
  • reMarkable Paper Pure 9
    The Quiet Revolution You Did Not Know You Needed
    • May 9, 2026
  • spain-qNO3XMQILTA-unsplash 10
    When the World Feels Unstable, Spain Remains the Calm. Here’s How to Get There Safely.
    • May 2, 2026
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • Anthropic Institute 1
    Introducing The Anthropic Institute
    • March 11, 2026
  • 2
    Why The CLOUD Act And Geopolitics Are Forcing A Data Sovereignty Reckoning In Europe
    • May 2, 2026
  • Red Hat OpenShift 3
    Red Hat Further Drives Digital Sovereignty for the AI Era with Red Hat OpenShift on Google Cloud Dedicated
    • April 21, 2026
  • Illustration of data storage 4
    The Splinternet Comes for European Supply Chains Why Fragmentation Is Now a Boardroom Problem
    • April 20, 2026
  • 5
    “A lot of other cloud vendors have been let off the hook”: Oracle leans hard on one-size-fits-all appeal of OCI for enterprises
    • March 30, 2026
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.