Blog Layout

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

Bill Doerrfeld | Dec 01, 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.


By Bill Doerrfeld 06 May, 2024
There's increasing interest in API strategies at the executive level. Leadership is realizing the operational benefits, seeing the monetization potential, and coming to terms with the need to govern a burgeoning catalog of services.
By Bill Doerrfeld 04 May, 2024
PostgreSQL is the database that quietly ate the world. Due to its simple and permissive license, community backing, and extensibility, PostgreSQL has silently found itself at the center of modern software development. I'm excited to share my new post on LeadDev that looks at the ubiquity of PostgreSQL, its history of slow and steady improvements, and why the community loves it so. I was surprised to see such positive responses from everyone I spoke with. I also like shining a light on a stable, open-source community project that's just been doing its thing for years. And years. And years... Thanks a lot to everyone who connected with me on this one! I'm looking forward to diving into areas like WebAssembly and open source AI in future articles for this presence. If you happen to have ideas or leads in those areas, feel free to reach out .
By Bill Doerrfeld 04 May, 2024
I was grateful to Apidays NYC for having me chat a bit on Day 2 about the types of trends we're noticing and covering on Nordic APIs . Had a great time sharing with you all! Mehdi Medjaoui and I discussed the role of AI in APIs, the need for heightened governance amid API ubiquity, the unbundling of API management, new design styles, and plenty of other topics. And yes, we made sure there was a crackling fire on the screen for our 'fireside chat.' 🔥😂 Here are some links to the resources I mentioned in our interview — basically an onboarding to Nordic APIs if you're unfamiliar with what we're up to. Blog Nordic APIs, supported by Curity , publishes thought pieces about the API economy every week. Check it out here . 𝗡𝗲𝘄𝘀𝗹𝗲𝘁𝘁𝗲𝗿 If you want to keep up-to-date with API news and tips, follow the newsletter here . 𝗪𝗿𝗶𝘁𝗶𝗻𝗴 If you have an API story to share and would like to write for the blog, we welcome submissions from the API community! Information on contributing is here . 𝗘𝘃𝗲𝗻𝘁𝘀 Nordic APIs is hosting a couple of yearly summits: the Platform Summit in Stockholm and the Austin API Summit in Austin, Texas. Registration for the next event, The Platform Summit, October 7-9, is now open . 𝗖𝗮𝗹𝗹 𝗙𝗼𝗿 𝗦𝗽𝗲𝗮𝗸𝗲𝗿𝘀 Nordic APIs has a rolling call for speakers for our events. The submission form is here .
By Bill Doerrfeld 23 Apr, 2024
I'm getting excited for this year's Platform Summit , to be held October 7-9 2024. Speaker submissions are now open! For those unaware, the Platform Summit is Nordic APIs' flagship API conference. Every year, we collect some of the brightest minds in the API industry for an intimate summit to discuss how to create top-tier API platforms. The event is now in its 7th year. I'm helping review submissions for the event and we've already got some great submissions. But, we'd love to feature more API case studies and welcome newcomers. Talk submission details are here . I'm also happy to chat if anyone would like to learn more or suggest topic ideas. Feel free to reach out on my contact page . Here's a playlist of sessions from Platform Summit 2023:
By Bill Doerrfeld 20 Apr, 2024
There are a lot of challenges in open source right now. From new licensing restrictions, supply chain issues, open source contributor equity, and beyond, there's a lot to consider. I've gathered input from some of the leading thought leaders in the open-source ecosystem to explore the top challenges facing open source and what the industry needs to evolve. This post is scheduled to publish on The New Stack on 5/7. I'll include a link when it's live!
By Bill Doerrfeld 04 Apr, 2024
My opening keynote from the Austin API Summit 2024 explores the similarities between producing hit albums and hit APIs. It's now published here on YouTube . As it turns out, making a hit API is a lot like making a hit music album. You have to find a niche, you need good naming, and you need quality content. Also, on the production side, design, style, experience, and collaboration all matter a lot. At the end of the day, both are products, requiring the right management tools, marketing know-how, and infrastructure to scale. In this SXSW-inspired opening keynote, I look into the parallels between the two endeavors, providing a fun and informative look into specific things API providers should be considering on their journey toward becoming API platform rockstars. 
By Bill Doerrfeld 25 Mar, 2024
How is AI evolving API management?
By Bill Doerrfeld 07 Feb, 2024
Calling all CIOs...
APIs are more relevant than ever
By Bill Doerrfeld 15 Nov, 2023
My opening keynote from the Platform Summit 2023 looks at the role APIs play in shaping our daily lives. It's now published on YouTube. APIs are increasingly in the public consciousness. In this keynote, I examine the role web APIs continue to play in the lives of both end users and software developers. From social media to generative AI, I briefly explore ome areas where APIs currently have the most impact. Whether you are a high-level architect or ground-floor engineer, this talk should provide helpful takeaways and inspire you to keep chugging along with your API-first platform designs.
By Bill Doerrfeld 03 Aug, 2021
Today I am thrilled to announce a major milestone update — v30.0! New features include: baby, house, dad responsibilities. This release is backward compatible with v2X.X but 1X.X is no longer supported.
More Posts
Share by: