dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README

commit 8c033fa06fd9593440bda4a6924a2dd3f3c3011b
parent 17c22f6c77eebdfbc2f320537e7762d2559b006c
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Wed, 28 Aug 2024 13:09:25 -0500

shell,scratchpad: Update status window (watch)

Diffstat:
M.config/bspwm/bspwmrc | 2+-
M.config/shell/functions.sh | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
M.local/bin/status.sh | 3++-
3 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/.config/bspwm/bspwmrc b/.config/bspwm/bspwmrc @@ -19,7 +19,7 @@ bspc rule -a latexocr state=floating bspc rule -a R_x11 state=floating bspc rule -a Screenkey manage=off bspc rule -a st-256color state=pseudo_tiled -bspc rule -a st-256color:*:watch state=floating +bspc rule -a st-256color:*:watch state=floating sticky=on bspc rule -a URxvt state=pseudo_tiled bspc rule -a Zathura state=tiled bspc rule -a qutebrowser locked=on diff --git a/.config/shell/functions.sh b/.config/shell/functions.sh @@ -145,7 +145,7 @@ check_imca() { current_date="$(date +%s)" if [ -f /tmp/check_imca ]; then - if [ $(cat /tmp/check_imca) -ne 200 ]; then + if [ "$(cat /tmp/check_imca || true)" -ne 200 ]; then next_check="$(($(stat -c %Y "/tmp/check_imca") + 1*60))" else next_check="$(($(stat -c %Y "/tmp/check_imca") + 15*60))" @@ -165,6 +165,48 @@ check_imca() { unset status_code } +check_exchange_rate() { + current_date="$(date +%s)" + + if [ -f /tmp/check_exchange_rate ]; then + if [ -z "$(cat /tmp/check_exchange_rate || true)" ]; then + next_check="$(($(stat -c %Y "/tmp/check_exchange_rate") + 1*60))" + else + next_check="$(($(stat -c %Y "/tmp/check_exchange_rate") + 15*60))" + fi + else + next_check="${current_date}" + fi + + + + + + if [ "${current_date}" -ge "${next_check}" ]; then + response=$( + curl -sS https://cuantoestaeldolar.pe/cambio-de-dolar-online | + sed "s/class>/>/g;s/class //g;s/defer //g;s/alt //g;s/defer>/>/g;s/data-n-p//g;s/data-n-g//g;s/data-n-css//g;s/nomodule //g" | + xpath -q -e "/html/body/div/main/div[3]/div/div[7]/div/div[1]" 2>/dev/null + ) + + + buy=$( + for i in $(seq 26); do + exchange=$(echo "${response}" | xpath -q -e "/div/div[${i}]/div[1]/div[6]/div/div[1]/p" 2>/dev/null | sed 's/<[^>]*>//g') + [ "${exchange}" != "0.000" ] && [ -n "${exchange}" ] && echo "${exchange}" + done | sort | tail -n 1 + ) + + sell=$( + for i in $(seq 26); do + exchange=$(echo "${response}" | xpath -q -e "/div/div[${i}]/div[1]/div[6]/div/div[2]/p" 2>/dev/null | sed 's/<[^>]*>//g') + [ "${exchange}" != "0.000" ] && [ -n "${exchange}" ] && echo "${exchange}" + done | sort | head -n 1 + ) + echo "${buy}" "${sell}"> /tmp/check_exchange_rate + fi +} + wm_status() { # Update RSS current_date="$(date +%s)" @@ -187,14 +229,14 @@ wm_status() { fi check_imca + check_exchange_rate status_news + exchange_rate } print_hello() { if [ -z "${TMUX}" ]; then - wm_status - output_tmux=$(tmux list-sessions 2>/dev/null) if [ -n "${output_tmux}" ]; then echo "# tmux sessions" @@ -204,3 +246,15 @@ print_hello() { unset output_tmux fi } + +exchange_rate() { + read -r buy sell < /tmp/check_exchange_rate + + echo "# cuantoestaeldolar.pe" + { + echo "buy: ${buy}" + echo "sell: ${sell}" + } | column + + unset response exchange +} diff --git a/.local/bin/status.sh b/.local/bin/status.sh @@ -2,10 +2,11 @@ winid=$(xdotool search --name watch) visible_winid=$(xdotool search --onlyvisible --name watch) +echo $winid if [ -z "${winid}" ]; then - nohup st -t watch -e bash -c 'while true; do watch --interval 60 --chgexit ". ~/.config/shell/functions.sh; wm_status"; notify-send "Status changed"; done' >/dev/null 2>/dev/null </dev/null & + nohup st -t watch -e bash -c 'while true; do watch --interval 60 --chgexit ". ~/.config/shell/functions.sh; wm_status"; echo notify-send "Status changed"; done' >/dev/null 2>/dev/null </dev/null & else if [ -z "${visible_winid}" ]; then xdo show "${winid}"