Command Line Weather One-Liner

This one-liner I crafted below will fetch a local weather report for different cities using the web service A full breakdown of its features and functions can be found on the projects GitHub page.

Perl One-Liner

perl -MLWP::Simple -se 'BEGIN {print qq~[J\033[H\033[J~}; map { getprint qq~${_}?format=${query}~; print qq~\n\n~; sleep 1} split m~,~, $loc' -- -query='%l:+%c+%C\nTemperature:+%t\nFeels+Like:++%f\nWind:+%w\nHumidity:+%h\nPressure:+%P\nPrecipitation:+%p\nLocal+Time:+%Z\nSunrise:+%S\nSunset:++%s\n' -loc='Toronto,Penetanguishene,Montreal'

Perl Breakdown

I am using the Module LWP::Simple. Normally this is included by default in a Perl installation but I have seen some instances where this was not included. So you may need to install it to make it work.

For the one-liner below replace -loc="City1,City2,City3" with the cities you wish to fetch the weather for.

The query="<query>" part can be adjusted to change how the weather is displayed. See below for more details.

Query Breakdown

Note: + = space.

  • %c – Weather condition
  • %C – Weather condition textual name
  • %x – weather contidion, plain-text symbol
  • %h – Humidity
  • %t – Temperature (Actual)
  • %f – Temperature (Feels Like)
  • %w – Wind
  • %l – Location
  • %m – Moonphase πŸŒ‘πŸŒ’πŸŒ“πŸŒ”πŸŒ•πŸŒ–πŸŒ—πŸŒ˜
  • %M – Moonday
  • %p – precipitation (mm/3 hours)
  • %P – pressure (hPa)
  • %D – Dawn
  • %S – Sunrise
  • %z – Zenith
  • %s – Sunset
  • %d – Dusk
  • %T – current time
  • %Z – local timezone

(*times are shown in the local timezone)


Latest Blogs

Leave a Reply