Episode: 2919 Title: HPR2919: hosting software in HPR show notes Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2919/hpr2919.mp3 Transcribed: 2025-10-24 13:15:54 --- this in HBR episode 2919 entitled Hosting Software in HBR Show Notes and in part of the series programming 101 it is hosted by Genre and in about 10 minutes long and Karima Cleanflag. The summer is, notes are awesome, but might lead to Hosting Software in the HBR Show Notes. This episode of HBR is brought to you by an honesthost.com. Get 15% discount on all shared hosting with the offer code HBR15. That's HBR15. Better web hosting that's honest and fair at An Honesthost.com. Hello HBR listeners, my name is Jezra and I bought a canoe. To be fair the canoe is not what this episode is about. With that in mind I'm going to tell you a bit more about the canoe. The canoe is a red 16 foot long prospector model manufactured by Winona. It is the special Lewis and Clark edition so presumably it was manufactured in 2005. For those who are curious this episode is about software and consuming an API and I will get to that in a bit but first let's get back to this boat. After a bit of paddling in a little pond I decided that this boat needs to have a clamp on mount for an electric motor so I built a little clamp on mount mounted it on the canoe put on the electric motor out of the battery went out in a little pond to test it out hit full throttle to see how it's going to go and I did a wheelie in a canoe flipped it over I went for a swim. Sadly my beloved Nexus 5X phone was in my pocket and it was kind of ruined by the experience. Bomber dude obviously the canoe was telling me no way bro you're not putting a motor on me I'm a canoe I should probably have a sail. With that inspiration I designed and built a clamp on sailing system for this canoe I built a rudder and a tiller and some outriggers for flotation and a mast and I sewed a sail out of a tarp so I could get this boat on some water and actually go sailing. On Labor Day weekend I took the canoe and sail rig to Scotts Flat Lake it's a local lake to go test it out but the canoe and the water put all the components on it and I went sailing sort of there wasn't much went however I did manage to see a bald eagle pluck a fish from the lake oh it was so close it was amazing absolutely amazing but man I did a lot of paddling that day a lot I should not have paddled so much but I had to because there was not much wind if only there was something I could do about such things. Fortunately for me the U.S. National Weather Service has an API where one can send GPS coordinates latitude and longitude and get information about weather in that area as well as a forecast for weather in that area and that forecast includes wind information. That's a racer. The API provided by the National Weather Service is a web accessible API which means that the data available on the API is accessible through any programming language that can make a request for a web page or I should say for the contents of a web page armed with this knowledge I crafted a plan. I would write a script that would access the data from the API and if the wind speed were above a certain threshold I would get a text message saying at this date the wind speed will be above this certain threshold at which point I would say wow I've got a lot to do that day sadly I can't go out sailing on the lake but it would be nice to know that that would be a good day to go out sailing on the lake. Now that the need has been explained I'm going to call this episode how not to release software and I say that because in the comments of an HPR episode is the worst place to release software well maybe not the worst place but you know I could use some sort of external software hosting service oh I guess that's what HPR is now never mind this episode is now called please host your software in the comment section of an HPR episode. In my web browser I opened up the Google Maps website found the very center of the lake where I would like to get the wind speed did right click something or other figured out the latitude and longitudinal points and put them in my script. The script is written using the Python programming language it is using the URL lib library for accessing the URL for accessing the API URL. Also used is the JSON library for processing the data returned by the API. The regular expression libraries also used because I need to process some numbers in text and the subprocess library is used which is an excellent way for me to run my text Jesra script from within another script. After my wind checking script imports the libraries that are used I declare some variable properties latitude and longitude agent which represents the user agent string sent to the API. The National Weather Service documentation specifically states that having a unique user agent string is the best way to keep the request from getting blocked. It's possible that they get spammed a lot or bots that have a non-unique string hammer their API. I'm not sure why they have that policy but they have that policy. I also set a variable called MinSpeed and MinSpeed represents the minimum wind speed in miles per hour that is necessary for triggering the text to myself saying the wind is good. I set that speed at nine miles per hour. If the wind is going to be below that I don't need a text message to tell me but if it's going to be nine miles per hour or more I'm your Hegelberry. Because the wind check script needs to get data from two different API endpoints that is to say it needs to get data from two different URLs. I created a function called get API data and that is passed the URL that the script needs to get data from. A request is made to the URL. It includes the user agent string and the data that gets returned is passed from JSON into a Python object and then the function returns that Python object back to the script so that it's one easy place to maintain accessing an API converting the returned JSON data to a Python object and then having access to that Python object. The first API request gets data about that specific GPS coordinate point within that returned data is a URL to get forecast data for that GPS location. So again this is the second time that the get API data function is called to get the forecast data for that endpoint and it gets returned as a Python object. The returned forecast data has periods and periods have name and wind speed as properties. So it will be things like Tuesday evening Wednesday Wednesday evening actually I guess it's Wednesday night. Those would be the names of the periods for the forecast. Wind speed is always going to be in one of two formats either number MPH or number to other number MPH. That is to say it could be five miles per hour or five to seven miles per hour or five to nine miles per hour. And this brings us to the second function of this script which is called wind is good and it's just past the wind speed string. Knowing that the wind speed string will either be number MPH or number to number MPH. The wind is good function uses a regular expression to find all matches of a number. And then it goes through those numbers that are matched to see if any of them are above the minimum speed or sorry I should say above or equal to the minimum speed. As the current minimum speed is nine if the wind speed were nine miles per hour then that would return true. If the wind speed were five to nine miles per hour that would also return true. Four to ten miles per hour again would return true. Four to seven miles per hour would return false. Regular expressions are great for such things. Boyle down to its simplest form. The script does this. Gets data for a point. Finds the forecasts for that point. Loops through the forecasts. Looking for a wind speed that is greater than nine miles per hour. If one is found, run text Jezra with the name of the forecast period and the wind speed of the forecast period. And that's it. Hope you enjoyed the episode. Timezone appropriate farewell to you. You've been listening to Hacker Public Radio at Hacker Public Radio dot org. We are a community podcast network that releases shows every weekday Monday through Friday. Today's show, like all our shows, was contributed by an HBR listener like yourself. If you ever thought of recording a podcast and click on our contributing to find out how easy it Hacker Public Radio was founded by the digital dog pound and the infonomicant computer club. And it's part of the binary revolution at binrev.com. If you have comments on today's show, please email the host directly, leave a comment on the website or record a follow-up episode yourself. Unless otherwise stated, today's show is released on the creative comments, attribution, share a light, free dot org license.