Weedr

Usage

You may call to https://weedr.belz.dev/XXXXX to get a valid Forecast7 weather url. This is useful if you have a need to provide "on-the-fly" weather-widgets from a source like WeatherWidget.io. The way I generally accomplish this is by using their widget generator to create a base widget like:

Widget from WeatherWidget.io

<a class="weatherwidget-io" href="https://forecast7.com/en/40d71n74d01/new-york/" data-label_1="NEW YORK" data-label_2="WEATHER" data-theme="original">NEW YORK WEATHER</a>
<script>
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src='https://weatherwidget.io/js/widget.min.js';fjs.parentNode.insertBefore(js,fjs);}}(document,'script','weatherwidget-io-js');
</script>

Take note of the href being https://forecast7.com/en/40d71n74d01/new-york/ and the data-label_1 along with the content of the anchor being/including NEW YORK. This is significant because, this service allows you to create a new url so you may programmatically replace the https://forecast7.com/en/40d71n74d01/new-york/ with something like https://forecast7.com/en/38d91n77d02/20001/ which was generated using a GET request to https://weedr.belz.dev/20001 and using the BODY of the response. Obviously you must replace the 20001 with your zipcode of choice. Also - if you get a 422 - it means Forecast7 can't use the zipcode you provided - so it's not this service's fault. Finally I replaced the content and data-label_1 attribute on the anchor to be WASHINGTON DC. Below is a Laravel component that expects two props, url, title which - this service can provide URL, if given a zipcode. So for example - I am making a SaaS which allows users to add their property and the application will make a forward-facing page available. I would like my users to enable a weather widget feature - but I don't want them having to manually do this, so I use the City and Zipcode they've signed up their property with, and this service, and voilĂ ; working weather widget. Oh and don't remove the trailing slash. It breaks the regex of Forecast7.

Laravel component

<a class="weatherwidget-io" href="{{ $url }}" data-label_1="{{ $title }}" data-label_2="WEATHER" data-theme="original">{{ $title }} WEATHER</a>
<script>
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src='https://weatherwidget.io/js/widget.min.js';fjs.parentNode.insertBefore(js,fjs);}}(document,'script','weatherwidget-io-js');
</script>

The result

WASHINGTON DC WEATHER

Attribution and project information

This project filled my need - it may or may not assist another out there, so I made it public. Though, I make no revenue from the public facing side of this service. The repository is here and attribution is certainly given to: