I wanted to have a home page that was actually useful. Because I like to travel, that means I want to know where I am, know the current weather, and the current time.
To do this, my system, in short, gets my location in latitude and longitude, translates that to the nearest city, gets the weather from the nearest openweathermap.org reporting site, translating that temperature into a color, then finally going to Flickr with search terms '<city name>' and 'sky conditions' and gathering the 10 most interesting photos. I used to include "skyline" which resulted in spectacular photos of Manhattan, but when you are in Tucumcari, NM, "skyline" gets you zero photos.
Note, because Covid-19 has clipped my wings, the home page now shows more aspirational locations than tracking me. I have grabbed a JSON file listing the top 1500 by population and pick a random one. The rest is the same, takes location, grabs the weather and slideshow and puts the page together.
I don't want to be tracked 24 hours a day, so I decided not to use Apple or Google's location APIs. I opted instead for Swarm (formerly Foursquare) that allowed me to check in when I wanted. That way I get a nice location feed with latitude and longitude, but only when I choose.
There are a number of weather APIs out there and they're fairly easy to use. In the next iteration of this page, I'll probably do a failover system with multiple sources, but for now it is just a single API, openweathermap.org, that offers a free system. My web server originally was setup to go to Swarm, go get the weather, and then return for further processing, but that took too much time. I then set up a cron job that would check for my location and weather every 30 seconds, but that violated my "free" status on weather.com (only so many lookups per day). So I settled on a very safe10 minute increment - every ten minutes, the server checks for my location, gets the location and then finds the nearest weather report and gathers that information.
The temeperature is then converted into a color (using NOAA map colors) and the navbar is changed to that translucent hue. I chose to use translucence because it is super cool AND since the background photo is random, translucence lets you 'cheat' and make the colorkind of coordinate with the photo's colors.
The temperature color is then sent into a 'split complementary' function:
getSplits($degree){ $splits = array(); $splits[0] = $degree+160; $splits[1] = $degree+210; for($i=0; $i<$splits.length; $i++){ if($splits[$i] > 360){ $splits[$i] = $splits[$i]-360; } } return $splits; }
These "splits" are then used as complementary colors for the nav and the Fuzzy Clock.
Finally, the weather information (temperature and sky conditions) are sent to the "Fuzzy Clock" section.
Flickr has a pretty cool API - lots of options, lots of filtering. In my case, I wanted to show the city I was in and that means a cityscape photo. The script takes the city name from the Swarm lookup and then goes to Flickr and searches for large images with the <city_name> + <sky conditions> as the search terms. It then sorts the results by "interestingness" and gathers the top ten most interesting matching images. This, plus the weather data and time, is written to a JSON file whenever my cron job is fired.
I like Fuzzy Clocks. Fuzzy Clocks tell you the time as a person would, in words. It turns out, though, language is a problem.
You don't say "It's noon in the morning" or "it's 0 minutes past two". But you do say, "It is six in the evening" or "'round ten past two in the afternoon." This does not translate easily into if/then statments. It is, in fact, a decision tree with many possible outcomes.
Here is the full text of Fuzzy Clock:
Chris is in New York, San Francisco, Miami, Chicago, ... where it is cold cool nice warm hot and partly mostly cloudy, clear, raining, snowing, Sunday Monday Tuesday Wednesday Thursday Friday Saturday at ‘round ten quarter twenty half past ’til midnight. noon. one two three four five six seven eight nine ten eleven o’clock in the morning. afternoon. evening. at night.
The text block lists the cities where I most commonly am (or in the case of Chicago, where I wish I was), all possible temperature descriptions, as well as sky conditions, all days, all words needed to describe the time. The Fuzzy Clock PHP takes the data so far (location, sky conditions, time, and temperature) and translates then matches the word(s) that describe the location, and changes their class to insert the word "highlight." All the other text stays in the nearly transparent font.
By the way, the ellipsis after the cities is intentional. It is a target that is replaced when I check in elsewhere. For example, when I was in Cleveland, the '...' was replaced by "Cleveland."
I hope to make it more universal and encapsulated. I'd like it if any visitor could download all the scripts, enter their own API keys and have a cool useful home page. The problem, of course, is that so few people know how to do API keys that it would require some sort of login/accept snooping screen.