Blog Layout

Using Open Data APIs to Find Local Sunset, Sunrise, and Moon Phase

Bill Doerrfeld | December 1, 2020

While on vacation last year I had a little fun writing some basic API use cases. I just wanted some simple landing pages that would show me helpful celestial data. When is sunset in my local timezone? When is the sunrise? What phase is the moon in?


You can view these three websites here: Sunset, Sunrise, Phase. Each should calculate each question correctly based on your local timezone. Below, I explain the process and link to the Github repos. 


sunset 🌇

Github

sunset is a super simple website that uses open data APIs to display the sunset time in your local timezone. Sunset demonstrates how to use HTTP GET calls to open data APIs. First, the code calls the GeoIPLookup.io API to return latitude and longitude coordinates based on the caller's IP address. Next, it passes these coordinates as parameters in a call to the Sunrise-Sunset API. The Sunrise-Sunset API returns the UTC timestamp for the sunset time. Lastly, sunset converts UTC into local time. It uses some JS functions to do that, and some janky slice methods to output what we want to see.


sunrise 🌄

Github

Sunrise is a super simple website that uses open data APIs to display the sunrise time in your local timezone. Sunrise demonstrates how to use HTTP GET calls to open data APIs. First, the code calls the GeoIPLookup.io API to return latitude and longitude coordinates based on the caller's IP address. Next, it uses passes these coordinates as parameters in a call to the Sunrise-Sunset API. The Sunrise-Sunset API returns the UTC timestamp for the sunrise time. Lastly, sunrise converts UTC into local time. It uses some JS functions to do that, and some janky slice methods to output what we want to see.


phase 🌘

Github

The moon is pretty lit. But just how lit is it? This simple one page site visually represents the current phase of the moon. I built it to demo an introductory example of practical API use cases. It's just a phase. phase calls the Farmsense API to display moon data. The Farmsense API is a free-to-use open API that returns useful moon phase and illumination data. After much research, it was the only free service I could find that returned the data I wanted. Given a unix timestamp, Farmsense returns information on the current moon phase, illumination percentage, and colloquial phase name. Depending on what the API returns, the script loads different images to reflect the current moon phase and illumination percentage. I also added a little bit of my own scientific interpretation on how lit the moon is.


🌘🌓🌔🌕🌖🌗🌒


Disclaimer

I built these projects to demo an introductory lesson on practical API use cases. As they are strictly demos they are not that great. Since Sunset and Sunrise depend on the caller's IP address, mobile use may return an incorrect time. Code is not elegant, it's just for sample purposes.


Study reveals growing technical debt in AI age
By Bill Doerrfeld February 19, 2025
The 2nd annual code quality report from GitClear found 10x more duplicated code than two years ago and fewer signs of code reuse than ever before.
Kubernetes usability InfoWorld pilot cockpit Doerrfeld
By Bill Doerrfeld February 10, 2025
My feature on InfoWorld explores the state of Kubernetes usability, highlighting various advancements across workload types, support for edge and AI, and new features like observability and security.
Carving out time for large-scale engineering chores
By Bill Doerrfeld January 31, 2025
It's up to leadership to help prioritize large-scale engineering updates that keep software running smoothly. Kent Wills, Director of Engineering at Yelp, provides insight on the latest DirectorPlus.
5 potential use cases for Arazzo
By Bill Doerrfeld January 30, 2025
Italian for “tapestry,” Arazzo is aptly named since it can be used to weave together sequences of API calls to illustrate a specific business pattern.
How genAI can aid Kubernetes troubleshooting
By Bill Doerrfeld December 23, 2024
I caught up with CTO Itiel Shwartz about leveraging finely tuned models like Komodor’s KlaudiaAI agent for ultra-specific DevOps challenges, like Kubernetes error diagnosis and remediation challenges.
Framing AI in the right light
By Bill Doerrfeld December 20, 2024
Rolling out AI is all about framing it in a positive light, says GitLab's CTO, Sabrina Farmer. I interviewed her for the latest edition of DirectorPlus for LeadDev, which is out today.
What's on the top of CIOs' minds lately? Resilience.
By Bill Doerrfeld December 19, 2024
Surmounting risks are encouraging CIOs to future-proof and update their resilience strategies. My latest feature for CIO.com explores resilience head-on.
DX Core 4 unifies developer productivity frameworks
By Bill Doerrfeld December 10, 2024
Today, DX debuted a new developer productivity framework, DX Core 4. Excited to break the news with LeadDev, interviewing one of the designers of the framework.
Migrating to microservices at MACH-speed
By Bill Doerrfeld December 2, 2024
In this issue of DirectorPlus, Gus Fune shares the story behind reverse engineering a monolithic e-commerce platform following MACH principles, which stands for microservices, APIs, cloud-native, and headless.
How spec-first API documentation aids partner integration
By Bill Doerrfeld November 29, 2024
Having good API documentation is one thing. Being specification-first is next level. Here are the benefits a specification-driven, git-based approach to documentation can bring to partner API integrations.
More Posts
Share by: