
Lukas - https://unsplash.com/photos/a-computer-screen-with-a-lot-of-data-on-it-MU8w72PzRow
Using the wttr.in service, you can get weather forecasts on your terminal. The following Perl script (weather.pl) displays the forecast for the next three days:
#!/usr/bin/perl use strict; if (@ARGV > 1 or !@ARGV) { print "Usage: weather.pl [ location ]\n"; print "location examples: Madrid, madrid\n"; print "'moon' as location for lunar phase\n"; exit; } # Examples: Madrid, madrid # 'moon' as argument for lunar phase system("curl wttr.in/$ARGV[0]");
Run without arguments, the script returns the syntax for execution:
Usage: weather.pl [ location ] location examples: Madrid, madrid 'moon' as location for lunar phase
The program accepts a single argument, which can be the name of a place, the postcode, or the keyword moon. For example:

The moon argument prints the moon phase to the terminal:

The following script (weather-moon.pl) does a little more than weather.pl:
#!/usr/bin/perl use strict; use POSIX qw(strftime); if (@ARGV != 1) { print "Usage: weather.pl [ location ]\n"; print "location examples: Madrid, madrid\n"; print "'moon' as location for lunar phase\n"; exit; } $ARGV[0] = lc($ARGV[0]); `~/sh-scripts/weather.pl $ARGV[0] > /tmp/weather-location 2>/dev/null`; `echo > /tmp/weather-moon; echo >> /tmp/weather-moon; echo >> /tmp/weather-moon; echo >> /tmp/weather-moon; echo >> /tmp/weather-moon; echo >> /tmp/weather-moon; echo >> /tmp/weather-moon; echo >> /tmp/weather-moon; echo >> /tmp/weather-moon; ~/sh-scripts/weather.pl moon >> /tmp/weather-moon 2>/dev/null`; `sed -i 's/Follow .*\@igor_chubin.* for wttr.in updates//g' /tmp/weather-location`; `sed -i '\$d' /tmp/weather-location`; `sed -i 's/Follow .*\@igor_chubin.* for wttr.in updates//g' /tmp/weather-moon`; `sed -i '\$d' /tmp/weather-moon`; if ($ARGV[0] eq "moon") { # Idea found in https://github.com/desertplant/moon-phase-background # In the script, the author update the background image with the moon # phase downloaded as image from Nasa web my $d1 = int(strftime("%j", gmtime)); my $d2 = int(strftime("%H", gmtime)); my $str = sprintf("%04d", $d1 * 24 - 23 + $d2); my $im = "moon.$str.tif"; # Big image # my $url = "https://svs.gsfc.nasa.gov/vis/a000000/a005400/a005415/frames/5760x3240_16x9_30p/plain/$im"; # Medium image my $url = "https://svs.gsfc.nasa.gov/vis/a000000/a005400/a005415/frames/3840x2160_16x9_30p/plain/$im"; `wget -O /tmp/$im $url`; system("chafa -c full --color-space din99d --work 9 --align left --scale max --font-ratio 0.38 --optimize 9 '/tmp/$im'"); } else { system("paste /tmp/weather-location /tmp/weather-moon"); }
The syntax is the same as for weather.pl. The script allows you to simultaneously display the weather forecast for the next three days and the lunar phase:

If the moon argument is specified, weather-moon.pl does not generate an ASCII drawing of the moon phase but downloads the image for the current day from the NASA website (thanks to Christopher Canty for his work and the idea). The script requires the chafa and wget programs to be installed. chafa allows the image to be displayed in the terminal. On Debian-like systems:
sudo [ aptitude | apt ] install chafa wget
weather-moon.pl generates this result:

The image resolution depends on the capabilities of the terminal. Kitty, for example, displays the image perfectly, without any tearing or artifacts. The image above was generated by running the script from Emacs‘ EAF-terminal.
The NASA repository contains frames (hourly images) of the lunar phase throughout the year, but the URL where the images reside may change each year, which may require updating the weather-moon.pl script. To find the correct path, you can refer to the internal link for the lunar phase image for the current day on the NASA website: https://svs.gsfc.nasa.gov/gallery/moonphase/. The base URL specified in weather-moon.pl (https://svs.gsfc.nasa.gov/vis/a000000/a005400/a005415/frames/3840x2160_16x9_30p/plain/) is valid for the year 2025.