Update: wttr.in now has a new one line format. So some of the below logic for parsing the output is no longer required.
I recently started using i3wm because it is light-weight, keyboard-friendly and uses the screen real-estate efficiently. I customized i3bar and i3status (which came installed with i3) to show system information and date/time. But there was no out-of-the-box feature to get weather information from i3 status.
I wanted a simple solution that does not require installing an external program like i3blocks, conky, dzen2, xmobar or lemonbar. It had to also preserve colors I had configured for the i3bar output. So I came up with this simple solution.
Step 1: Setup a cron job to retrieve weather information every 5 minutes and store it in a temporary file. (This is because wttr.in only allows 1000 API calls per day and the weather information is not frequently updated in the server.)
*/5 * * * * curl -s wttr.in/montreal?T | head -n 7 > ~/.weather.cache
Step 2: Write a shell script to add this information to i3status data.
Step 3: The ~/.config/i3/config file needs to be updated for the status_command to pipe through this script, as follows.
bar {
status_command .config/i3/weather.sh
tray_output primary
}
Step 4: The ~/.i3status.conf file should also be updated to change the output to the JSON format.
general {
output_format = "i3bar"
colors = true
interval = 5
}
This is how it looks like in the end.
You can find more information from the following links.
I wanted a simple solution that does not require installing an external program like i3blocks, conky, dzen2, xmobar or lemonbar. It had to also preserve colors I had configured for the i3bar output. So I came up with this simple solution.
Step 1: Setup a cron job to retrieve weather information every 5 minutes and store it in a temporary file. (This is because wttr.in only allows 1000 API calls per day and the weather information is not frequently updated in the server.)
*/5 * * * * curl -s wttr.in/montreal?T | head -n 7 > ~/.weather.cache
Step 2: Write a shell script to add this information to i3status data.
Step 3: The ~/.config/i3/config file needs to be updated for the status_command to pipe through this script, as follows.
bar {
status_command .config/i3/weather.sh
tray_output primary
}
Step 4: The ~/.i3status.conf file should also be updated to change the output to the JSON format.
general {
output_format = "i3bar"
colors = true
interval = 5
}
This is how it looks like in the end.
You can find more information from the following links.
Exactly what I needed ! Thanks !
ReplyDelete