Skip to content

Commit

Permalink
rofi-wttr: Weather display with forecast popup (vivien#451)
Browse files Browse the repository at this point in the history
rofi-wttr: Weather display with forecast popup

A minimal weather line with forecast pop up on click. Using rofi for the pop up and wttr.in as the weather interface.
  • Loading branch information
lomky authored May 13, 2022
1 parent 839d874 commit 46cdab5
Show file tree
Hide file tree
Showing 7 changed files with 783 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ This repository contains a set of scripts (a.k.a. *blocklets*) for link:https://
| link:monitor_manager[] | Manage monitor on/off, resolution, extend, clone
| link:nm-vpn[] | Show vpn status using network manager
| link:openvpn[] | Show openvpn status
| link:rofi-calendar[] | Current date/time and click for callendar using rofi
| link:rofi-calendar[] | Current date/time and click for calendar using rofi
| link:rofi-wttr[] | Current weather and click for weather forecast using rofi
| link:shutdown_menu[] | Shutdown menu using rofi or zenity
| link:systemctl[] | Startup and Shutdown system services
| link:tahoe-lafs[] | Show status of your tahoe-lafs grid
Expand Down
661 changes: 661 additions & 0 deletions rofi-wttr/LICENSE.md

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions rofi-wttr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# rofi-wttr

A minimal weather line with forecast pop up on click. Using [rofi](https://github.com/davatorium/rofi) for the pop up and [wttr.in](https://wttr.in/) as the weather interface.

![The statusbar weather](rofi-wttr-status-line.png)
The statusbar

![The weather forecast popup](rofi-wttr-detail.png)
The popup with the default rofi theme

## Depencencies

* [rofi](https://github.com/davatorium/rofi)
* curl

## Installation

* Copy the script into your directory of choice, e.g. ~/.i3blocks/blocklets
* Give it execution permission (`chmod +x rofi-wttr`)
* Optional: Customize your rofi theme via the `rofi-theme-selector` command
* Optional: Customize the rofi launch options in the script
* Optional: Customize the wttr curl arguments in the script
* Add the following blocklet to your i3blocks.conf:

```ini
[rofi-wttr]
command=$SCRIPT_DIR/rofi-wttr
interval=3600
#BAR_POSITION=top
#FONT=Monospace 10
#LABEL=🌡️
#LOCATION=Washington_DC
#ROFI_CONFIG_FILE=/dev/null
```

## Thanks
Modeled off of [rofi-calendar](https://github.com/vivien/i3blocks-contrib/tree/master/rofi-calendar) with thanks to its authors.
8 changes: 8 additions & 0 deletions rofi-wttr/i3blocks.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[rofi-wttr]
command=$SCRIPT_DIR/rofi-wttr
interval=300
#BAR_POSITION=top
#FONT=Monospace 10
#LABEL=🌡️
#LOCATION=Washington_DC
#ROFI_CONFIG_FILE=/dev/null
75 changes: 75 additions & 0 deletions rofi-wttr/rofi-wttr
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#! /usr/bin/env bash

###### Variables ######
LABEL="${LABEL:- }"
LOCATION="${LOCATION:- }"
FONT="${FONT:-Monospace 10}"
ROFI_CONFIG_FILE="${ROFI_CONFIG_FILE:-/dev/null}"
BAR_POSITION="${BAR_POSITION:-bottom}"

###### Variables ######


###### Functions ######
# print the full weather
# see https://github.com/chubin/wttr.in#usage for full configuration options
print_weather_report() {
if [[ $LOCATION != "" ]]; then
curl https://wttr.in/$LOCATION?T
else
curl https://wttr.in/?T
fi
}

# print the one line weather
# see https://github.com/chubin/wttr.in#one-line-output for formatting options
print_weather_line() {
if [[ $LOCATION != "" ]]; then
curl -s https://wttr.in/${LOCATION}?u\&format="%C+%c+%t+(%f)+%w" | tr -d \"
else
curl -s 'https://wttr.in/?u\&format="%C+%c+%t+(%f)+%w"' | tr -d \"
fi
}

###### Functions ######


###### Main body ######

# handle any click
# rofi pop up
case "$BLOCK_BUTTON" in
1|2|3)
IFS=
weather_report=$(print_weather_report)

# check bar position and adjust anchor accordingly
if [[ $BAR_POSITION = "top" ]]; then
anchor="northwest"
else
anchor="southwest"
fi

# open rofi
# (add the following option to rofi command with proper config file, if needed)
echo $weather_report \
| rofi \
-dmenu \
-markup-rows \
-font $FONT \
-m -3 \
-theme-str 'window {width: 53%; anchor: '"$anchor"'; location: northwest;}' \
-theme-str 'listview {lines: '"$(echo $weather_report | wc -l)"' ;scrollbar: false;}' \
-theme $ROFI_CONFIG_FILE \
-p "Detailed weather report"
esac

# print blocklet text

if [[ $LABEL != "" ]]; then
echo $LABEL$(print_weather_line)
else
echo $(print_weather_line)
fi

###### Main body ######
Binary file added rofi-wttr/rofi-wttr-detail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rofi-wttr/rofi-wttr-status-line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 46cdab5

Please sign in to comment.