💾 Archived View for dj-chase.com › documents › mutt-cron-text-yourself-weather.t2t captured on 2024-08-18 at 18:16:01.
⬅️ Previous capture (2023-07-10)
-=-=-=-=-=-=-
Using mutt & cron To Text Yourself The Weather en I have a flip phone (it’s much less distracting than a smartphone), so I cannot use an app or a browser to check the weather when getting dressed in the morning. I tried NOAA’s dial-a-forecast, but the number for my state is out of service. So, I decided to make a script that texts me the weather. This was surprisingly simple. It broke down into three steps: + Get the weather + Text it to myself + Automate that This post assumes that you have email working on a system-level. Since setting that up is out-of-scope for this post, you can either do it yourself or get an account on a [pubnix https://tildeverse.org/]. == Step one: getting the weather == There are two ways I went about this. At first, I just used wttr.in in image-mode (to avoid text-wrapping issues). This worked well but I generally prefer NOAA’s forecast, so I eventually switched to the weather.gov API. [wttr.in https://wttr.in/:help] [weather.gov API https://www.weather.gov/documentation/services-web-api] The wttr-version of the script looks like this:
umask -S u=rw,g=,o= > /dev/null
unset WEATHER
trap 'rm -f "$WEATHER"' INT TERM HUP EXIT
WEATHER="/tmp/$.$USER.$(awk 'BEGIN{srand(); print rand()}').png"
:> "$WEATHER"
curl --silent https://wttr.in/LOCATION.png?1Fqn > "$WEATHER"
Replace //LOCATION// with your location / zip-code. == Step two: texting it to myself == Now that we have the weather, it’s time to text it. I thought this part would be challenging, but it turned out to be very simple. I found out that most US carriers provide an email-to-MMS gateway, which meant that I could just send myself an email and it would show up as a text. I chose mutt instead of something POSIXly correct because attachments are really simple with mutt, and this is just a hack. The full script now looks like this:
umask -S u=rw,g=,o= > /dev/null
unset WEATHER
trap 'rm -f "$WEATHER"' INT TERM HUP EXIT
WEATHER="/tmp/$.$USER.$(awk 'BEGIN{srand(); print rand()}').png"
:> "$WEATHER"
curl --silent https://wttr.in/LOCATION.png?1Fqn > "$WEATHER"
mutt -a "$WEATHER" -- 8005551234@mms-gateway.example
== Step three: automating it == I then had a script that texted me the weather when run, but I wanted to get the weather every morning. To do this, I just made a simple cronjob (``run crontab -e``):
0 10 * * * /home/u9000/bin/pushweather.sh
That’s it. This project was surprisingly simple but very fun, and I use it daily.