updates
This commit is contained in:
1 parent
3dab288c51
commit
b25e81d1a3
35 files changed
+422
-772
No files matched your search
@@ -1,177 +0,0 @@
|
||||
#!/bin/bash
|
||||
trap resume_processes SIGINT
|
||||
in_range() { local num=$1 local min=$2 local max=$3 ; [[ $num =~ ^[0-9]+$ ]] && (( num >= min && num <= max )); }
|
||||
mnc=5 mxc=80 mnl=20 mxl=50 mnu=80 mxu=100 mnt=60 mxt=1000 mnf=80 mxf=100 mnn=1 mxn=60 mni=1 mxi=10 verbose=false undock=false #Defaults Ranges
|
||||
while (( "$#" )); do # Parse command-line arguments and defaults
|
||||
case "$1" in
|
||||
"--full"|"-f") if in_range "$2" $mnf $mxf; then battery_full_threshold=$2 ; shift 2 ; else echo "$1 Error: Full Threshold must be $mnf - $mxf." >&2 ; exit 1 ; fi;;
|
||||
"--critical"|"-c") if in_range "$2" $mnc $mxc; then battery_critical_threshold=$2 ; shift 2 ; else echo "$1 ERROR: Critical Threshold must be $mnc - $mxc." >&2 ; exit 1 ; fi;;
|
||||
"--low"|"-l") if in_range "$2" $mnl $mnu; then battery_low_threshold=$2 ; shift 2 ; else echo "$1 ERROR: Low Threshold $mnl - $mnu." >&2 ; exit 1 ; fi;;
|
||||
"--unplug"|"-u") if in_range "$2" $mnu $mxu; then unplug_charger_threshold=$2 ; shift 2 ; else echo "$1 ERROR: Unplug Threshold must be $mnu $mxu." >&2 ; exit 1 ; fi;;
|
||||
"--timer"|"-t") if in_range "$2" $mnt $mxt; then timer=$2 ; shift 2 ; else echo "$1 ERROR: Timer must be $mnt - $mxt." >&2 ; exit 1 ; fi;;
|
||||
"--notify"|"-n") if in_range "$2" $mnn $mxn; then notify=$2 ; shift 2 ; else echo "$1 ERROR: Notify must be $mnn - $mxn in minutes." >&2 ; exit 1 ; fi;;
|
||||
"--interval"|"-i") if in_range "$2" $mni $mxi; then interval=$2 ; shift 2 ; else echo "$1 ERROR: Interval must be by $mni% - $mxi% intervals." >&2 ; exit 1 ; fi;;
|
||||
"--verbose"|"-v") verbose=true ; shift ;;
|
||||
"--undock"|"on") undock=true ; shift ;;
|
||||
"--execute"|"-e") execute=$2 ; shift 2 ;;
|
||||
|
||||
*|"--help"|"-h")
|
||||
echo "Usage: $0 [options]"
|
||||
echo " --verbose, -v Verbose Mode"
|
||||
echo " --undock, on Shows Battery Plug In/Out/Full Notification"
|
||||
echo " --full, -f Set battery full threshold (default: 100% percent)"
|
||||
echo " --critical, -c Set battery critical threshold (default: 10% percent)"
|
||||
echo " --low, -l Set battery low threshold (default: 20% percent)"
|
||||
echo " --unplug, -u Set unplug charger threshold (default: 80% percent )"
|
||||
echo " --timer, -t Set countdown timer (default: 120 seconds)"
|
||||
echo " --interval, -i Set notify interval on LOW UNPLUG Status (default: 5% percent)"
|
||||
echo " --notify, -n Set notify interval for Battery Full Status (default: 1140 mins/ 1 day)"
|
||||
echo " --execute, -e Set command/script to execute if battery on critical threshold (default: systemctl suspend)"
|
||||
echo " --help, -h Show this help message
|
||||
Visit https://github.com/prasanthrangan/hyprdots for the Github Repo"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
is_laptop() { # Check if the system is a laptop
|
||||
if grep -q "Battery" /sys/class/power_supply/BAT*/type; then
|
||||
return 0 # It's a laptop
|
||||
else
|
||||
echo "Cannot Detect a Battery. If this seems an error please report an issue to https://github.com/prasanthrangan/hyprdots."
|
||||
exit 0 # It's not a laptop
|
||||
fi
|
||||
}
|
||||
fn_verbose () {
|
||||
if $verbose; then
|
||||
cat << VERBOSE
|
||||
=============================================
|
||||
Battery Status: $battery_status
|
||||
Battery Percentage: $battery_percentage
|
||||
=============================================
|
||||
|
||||
|
||||
VERBOSE
|
||||
fi
|
||||
}
|
||||
fn_notify () { # Send notification
|
||||
|
||||
notify-send -a "Power" $1 -u $2 "$3" "$4" -p # Call the notify-send command with the provided arguments \$1 is the flags \$2 is the urgency \$3 is the title \$4 is the message
|
||||
}
|
||||
fn_percentage () {
|
||||
if [[ "$battery_percentage" -ge "$unplug_charger_threshold" ]] && [[ "$battery_status" != "Discharging" ]] && [[ "$battery_status" != "Full" ]] && (( (battery_percentage - last_notified_percentage) >= $interval )); then if $verbose; then echo "Prompt:UNPLUG: $battery_unplug_threshold $battery_status $battery_percentage" ; fi
|
||||
fn_notify "-t 5000 " "CRITICAL" "Battery Charged" "Battery is at $battery_percentage%. You can unplug the charger!"
|
||||
last_notified_percentage=$battery_percentage
|
||||
elif [[ "$battery_percentage" -le "$battery_critical_threshold" ]]; then
|
||||
count=$(( timer > $mnt ? timer : $mnt )) # reset count
|
||||
while [ $count -gt 0 ] && [[ $battery_status == "Discharging"* ]]; do
|
||||
for battery in /sys/class/power_supply/BAT*; do battery_status=$(< "$battery/status") ; done
|
||||
if [[ $battery_status != "Discharging" ]] ; then break ; fi
|
||||
fn_notify "-t 5000 -r 69 " "CRITICAL" "Battery Critically Low" "$battery_percentage% is critically low. Device will execute $execute in $((count/60)):$((count%60)) ."
|
||||
count=$((count-1))
|
||||
sleep 1
|
||||
done
|
||||
[ $count -eq 0 ] && fn_action
|
||||
elif [[ "$battery_percentage" -le "$battery_low_threshold" ]] && [[ "$battery_status" == "Discharging" ]] && (( (last_notified_percentage - battery_percentage) >= $interval )); then if $verbose; then echo "Prompt:LOW: $battery_low_threshold $battery_status $battery_percentage" ; fi
|
||||
fn_notify "-t 5000 " "CRITICAL" "Battery Low" "Battery is at $battery_percentage%. Connect the charger."
|
||||
last_notified_percentage=$battery_percentage
|
||||
fi
|
||||
}
|
||||
fn_action () { #handles the $execute command
|
||||
count=$(( timer > $mnt ? timer : $mnt )) # reset count
|
||||
nohup $execute
|
||||
}
|
||||
|
||||
fn_status () {
|
||||
if [[ $battery_percentage -ge $battery_full_threshold ]] && [ "$battery_status" == *"Charging"* ]; then echo "Full and $battery_status"
|
||||
battery_status="Full" ;fi
|
||||
case "$battery_status" in # Handle the power supply status
|
||||
"Discharging") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi
|
||||
if [[ "$prev_status" != "Discharging" ]] || [[ "$prev_status" == "Full" ]] ; then
|
||||
prev_status=$battery_status
|
||||
urgency=$([[ $battery_percentage -le "$battery_low_threshold" ]] && echo "CRITICAL" || echo "NORMAL")
|
||||
fn_notify "-t 5000 -r 54321 " "$urgency" "Charger Plug OUT" "Battery is at $battery_percentage%."
|
||||
fi
|
||||
fn_percentage
|
||||
;;
|
||||
"Not"*|"Charging") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi
|
||||
# Due to modifications of some devices Not Charging after reaching 99 or limits
|
||||
#if [[ ! -f "/tmp/hyprdots.batterynotify.status.$battery_status-$$" ]] && [[ "$battery_status" == "Not"* ]] ; then
|
||||
#touch "/tmp/hyprdots.batterynotify.status.$battery_status-$$"
|
||||
#count=$(( timer > $mnt ? timer : $mnt )) # reset count
|
||||
#echo "Status: '==>> "$battery_status" <<==' Device Reports Not Charging!,This may be device Specific errors."
|
||||
#fn_notify "-t 5000 " "CRITICAL" "Charger Plug In" "Battery is at $battery_percentage%."
|
||||
#fi
|
||||
if [[ "$prev_status" == "Discharging" ]] || [[ "$prev_status" == "Not"* ]] ; then
|
||||
prev_status=$battery_status
|
||||
count=$(( timer > $mnt ? timer : $mnt )) # reset count
|
||||
urgency=$([[ "$battery_percentage" -ge $unplug_charger_threshold ]] && echo "CRITICAL" || echo "NORMAL")
|
||||
fn_notify "-t 5000 -r 54321 " "$urgency" "Charger Plug In" "Battery is at $battery_percentage%."
|
||||
fi
|
||||
fn_percentage
|
||||
;;
|
||||
"Full") if $verbose; then echo "Case:$battery_status Level: $battery_percentage" ;fi
|
||||
|
||||
if [[ $battery_status != "Discharging" ]]; then
|
||||
now=$(date +%s)
|
||||
if [[ "$prev_status" == *"harging"* ]] || ((now - lt >= $((notify*60)) )); then
|
||||
fn_notify "-t 5000 -r 54321" "CRITICAL" "Battery Full" "Please unplug your Charger"
|
||||
prev_status=$battery_status lt=$now
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if [[ ! -f "/tmp/hyprdots.batterynotify.status.fallback.$battery_status-$$" ]]; then
|
||||
echo "Status: '==>> "$battery_status" <<==' Script on Fallback mode,Unknown power supply status.Please copy this line and raise an issue to the Github Repo.Also run 'ls /tmp/hyprdots.batterynotify' to see the list of lock files.*"
|
||||
touch "/tmp/hyprdots.batterynotify.status.fallback.$battery_status-$$"
|
||||
fi
|
||||
fn_percentage
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
fn_status_change () { # Handle when status changes
|
||||
for battery in /sys/class/power_supply/BAT*; do battery_status=$(< "$battery/status") battery_percentage=$(< "$battery/capacity")
|
||||
if [ "$battery_status" != "$last_battery_status" ] || [ "$battery_percentage" != "$last_battery_percentage" ]; then last_battery_status=$battery_status last_battery_percentage=$battery_percentage # Check if battery status or percentage has changed
|
||||
fn_verbose
|
||||
fn_percentage
|
||||
if $undock; then fn_status echo yes ; fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
resume_processes() { for pid in $pids ; do if [ $pid -ne $current_pid ] ; then kill -CONT $pid ; notify-send -a "Battery Notify" -t 2000 -r 9889 -u "CRITICAL" "Debugging ENDED, Resuming Regular Process" ; fi ; done }
|
||||
main() { # Main function
|
||||
if is_laptop; then
|
||||
rm -fr /tmp/hyprdots.batterynotify* # Cleaning the lock file
|
||||
battery_full_threshold=${battery_full_threshold:-100}
|
||||
battery_critical_threshold=${battery_critical_threshold:-10}
|
||||
unplug_charger_threshold=${unplug_charger_threshold:-80}
|
||||
battery_low_threshold=${battery_low_threshold:-20}
|
||||
timer=${timer:-120}
|
||||
notify=${notify:-1140}
|
||||
interval=${interval:-5}
|
||||
|
||||
execute=${execute:-"systemctl suspend"}
|
||||
cat << EOF
|
||||
Script is running...
|
||||
Check $0 --help for options.
|
||||
|
||||
STATUS THRESHOLD INTERVAL
|
||||
Full $battery_full_threshold $notify Minutes
|
||||
Critical $battery_critical_threshold $timer Seconds then "$execute"
|
||||
Low $battery_low_threshold $interval Percent
|
||||
Unplug $unplug_charger_threshold $interval Percent
|
||||
|
||||
|
||||
EOF
|
||||
if $verbose; then for line in "Verbose Mode is ON..." "" "" "" "" ; do echo $line ; done;
|
||||
current_pid=$$
|
||||
pids=$(pgrep -f "/bin/bash $HOME/.config/hypr/scripts/batterynotify.sh" )
|
||||
for pid in $pids ; do if [ $pid -ne $current_pid ] ;then kill -STOP $pid ;notify-send -a "Battery Notify" -t 2000 -r 9889 -u "CRITICAL" "Debugging STARTED, Pausing Regular Process" ;fi ; done ; trap resume_processes SIGINT ; fi
|
||||
fn_status_change # initiate the function
|
||||
last_notified_percentage=$battery_percentage
|
||||
prev_status=$battery_status
|
||||
|
||||
dbus-monitor --system "type='signal',interface='org.freedesktop.DBus.Properties',path='$(upower -e | grep battery)'" 2> /dev/null | while read -r battery_status_change; do fn_status_change ; done
|
||||
fi
|
||||
}
|
||||
main
|
||||
@@ -1,115 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# Nuke all internal spawns when script dies
|
||||
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM
|
||||
|
||||
BARS=14;
|
||||
FRAMERATE=60;
|
||||
EQUILIZER=1;
|
||||
|
||||
# Get script options
|
||||
while getopts 'b:f:m:eh' flag; do
|
||||
case "${flag}" in
|
||||
b) BARS="${OPTARG}" ;;
|
||||
f) FRAMERATE="${OPTARG}" ;;
|
||||
e) EQUILIZER=0 ;;
|
||||
h)
|
||||
echo "caway usage: caway [ options ... ]"
|
||||
echo "where options include:"
|
||||
echo
|
||||
echo " -b <integer> (Number of bars to display. Default 8)"
|
||||
echo " -f <integer> (Framerate of the equilizer. Default 60)"
|
||||
echo " -e (Disable equilizer. Default enabled)"
|
||||
echo " -h (Show help message)"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
bar="▁▂▃▄▅▆▇█"
|
||||
dict="s/;//g;"
|
||||
|
||||
# creating "dictionary" to replace char with bar + thin space " "
|
||||
i=0
|
||||
while [ $i -lt ${#bar} ]
|
||||
do
|
||||
dict="${dict}s/$i/${bar:$i:1} /g;"
|
||||
i=$((i=i+1))
|
||||
done
|
||||
|
||||
# Remove last extra thin space
|
||||
dict="${dict}s/.$//;"
|
||||
|
||||
clean_create_pipe() {
|
||||
if [ -p $1 ]; then
|
||||
unlink $1
|
||||
fi
|
||||
mkfifo $1
|
||||
}
|
||||
|
||||
kill_pid_file() {
|
||||
if [[ -f $1 ]]; then
|
||||
while read pid; do
|
||||
{ kill "$pid" && wait "$pid"; } 2>/dev/null
|
||||
done < $1
|
||||
fi
|
||||
}
|
||||
|
||||
# PID of the cava process and while loop launched from the script
|
||||
cava_waybar_pid="/tmp/cava_waybar_pid"
|
||||
|
||||
# Clean pipe for cava
|
||||
cava_waybar_pipe="/tmp/cava_waybar.fifo"
|
||||
clean_create_pipe $cava_waybar_pipe
|
||||
|
||||
# Custom cava config
|
||||
cava_waybar_config="/tmp/cava_waybar_config"
|
||||
echo "
|
||||
[general]
|
||||
mode = normal
|
||||
framerate = $FRAMERATE
|
||||
bars = $BARS
|
||||
|
||||
[output]
|
||||
method = raw
|
||||
raw_target = $cava_waybar_pipe
|
||||
data_format = ascii
|
||||
ascii_max_range = 7
|
||||
" > $cava_waybar_config
|
||||
|
||||
# Clean pipe for playerctl
|
||||
playerctl_waybar_pipe="/tmp/playerctl_waybar.fifo"
|
||||
clean_create_pipe $playerctl_waybar_pipe
|
||||
|
||||
# playerctl output into playerctl_waybar_pipe
|
||||
playerctl -a metadata --format '{"text": "{{artist}} - {{title}}", "tooltip": "{{playerName}} : {{markup_escape(artist)}} - {{markup_escape(title)}}", "alt": "{{status}}", "class": "{{status}}"}' -F >$playerctl_waybar_pipe &
|
||||
|
||||
# Read the playerctl o/p via its fifo pipe
|
||||
while read -r line; do
|
||||
# Kill the cava process to stop the input to cava_waybar_pipe
|
||||
kill_pid_file $cava_waybar_pid
|
||||
|
||||
echo "$line" | jq --unbuffered --compact-output
|
||||
|
||||
# If the class says "Playing" and equilizer is enabled
|
||||
# then show the cava equilizer
|
||||
if [[ $EQUILIZER == 1 && $(echo $line | jq -r '.class') == 'Playing' ]]; then
|
||||
# Show the playing title for 2 seconds
|
||||
sleep 2
|
||||
|
||||
# cava output into cava_waybar_pipe
|
||||
cava -p $cava_waybar_config >$cava_waybar_pipe &
|
||||
|
||||
# Save the PID of child process
|
||||
echo $! > $cava_waybar_pid
|
||||
|
||||
# Read the cava o/p via its fifo pipe
|
||||
while read -r cmd2; do
|
||||
# Change the "text" key to bars
|
||||
echo "$line" | jq --arg a $(echo $cmd2 | sed "$dict") '.text = $a' --unbuffered --compact-output
|
||||
done < $cava_waybar_pipe & # Do this fifo read in background
|
||||
|
||||
# Save the while loop PID into the file as well
|
||||
echo $! >> $cava_waybar_pid
|
||||
fi
|
||||
done < $playerctl_waybar_pipe
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CONFIG=$(rofi -show file-browser-extended -file-browser-stdout -file-browser-dir "$HOME"/.config/keyb/bindings -config ~/.config/rofi/keybinds.rasi)
|
||||
|
||||
hyprctl dispatch exec "[float;size 45% 80%;center 1] kitty keyb -k '$CONFIG'"
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function random_hex() {
|
||||
random_hex=("0xff$(openssl rand -hex 3)")
|
||||
echo $random_hex
|
||||
}
|
||||
|
||||
hyprctl keyword general:col.active_border $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) 270deg
|
||||
|
||||
hyprctl keyword general:col.inactive_border $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) 270deg
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
wlsunset -t 4000 -T 6500 -d 900 -S 07:00 -s 19:00
|
||||
@@ -1,29 +0,0 @@
|
||||
# #! /bin/bash
|
||||
|
||||
#----- Optimized bars animation without much CPU usage increase --------
|
||||
bar="▁▂▃▄▅▆▇█"
|
||||
dict="s/;//g"
|
||||
|
||||
# Calculate the length of the bar outside the loop
|
||||
bar_length=${#bar}
|
||||
|
||||
# Create dictionary to replace char with bar
|
||||
for ((i = 0; i < bar_length; i++)); do
|
||||
dict+=";s/$i/${bar:$i:1}/g"
|
||||
done
|
||||
|
||||
# Create cava config
|
||||
config_file="/tmp/bar_cava_config"
|
||||
cat >"$config_file" <<EOF
|
||||
[general]
|
||||
bars = 10
|
||||
|
||||
[output]
|
||||
method = raw
|
||||
raw_target = /dev/stdout
|
||||
data_format = ascii
|
||||
ascii_max_range = 7
|
||||
EOF
|
||||
|
||||
# Read stdout from cava and perform substitution in a single sed command
|
||||
cava -p "$config_file" | sed -u "$dict"
|
||||
@@ -1,62 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# Define directories
|
||||
config_dir="$HOME/.config/waybar/configs"
|
||||
waybar_config="$HOME/.config/waybar/config"
|
||||
scripts_dir="$HOME/.config/hypr/scripts"
|
||||
rofi_config="$HOME/.config/rofi/config-waybar-layout.rasi"
|
||||
|
||||
# Function to display menu options
|
||||
menu() {
|
||||
options=()
|
||||
while IFS= read -r file; do
|
||||
options+=("$(basename "$file")")
|
||||
done < <(find "$config_dir" -maxdepth 1 -type f -exec basename {} \; | sort)
|
||||
|
||||
printf '%s\n' "${options[@]}"
|
||||
}
|
||||
|
||||
# Apply selected configuration
|
||||
apply_config() {
|
||||
ln -sf "$config_dir/$1" "$waybar_config"
|
||||
restart_waybar_if_needed
|
||||
}
|
||||
|
||||
# Restart Waybar
|
||||
restart_waybar_if_needed() {
|
||||
if pgrep -x "waybar" >/dev/null; then
|
||||
pkill waybar
|
||||
sleep 0.1 # Delay for Waybar to completely terminate
|
||||
fi
|
||||
"${scripts_dir}/Refresh.sh" &
|
||||
}
|
||||
|
||||
# Main function
|
||||
main() {
|
||||
choice=$(menu | rofi -dmenu -config "$rofi_config")
|
||||
|
||||
if [[ -z "$choice" ]]; then
|
||||
echo "No option selected. Exiting."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case $choice in
|
||||
"no panel")
|
||||
pgrep -x "waybar" && pkill waybar || true
|
||||
;;
|
||||
*)
|
||||
apply_config "$choice"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Kill Rofi if already running before execution
|
||||
if pgrep -x "rofi" >/dev/null; then
|
||||
pkill rofi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
main
|
||||
@@ -1,121 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# From https://raw.githubusercontent.com/rxyhn/dotfiles/main/home/rxyhn/modules/desktop/waybar/scripts/waybar-wttr.py
|
||||
|
||||
## ensure to insert city inside ""
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
|
||||
WEATHER_CODES = {
|
||||
'113': ' ',
|
||||
'116': ' ',
|
||||
'119': ' ',
|
||||
'122': ' ',
|
||||
'143': ' ',
|
||||
'176': ' ',
|
||||
'179': ' ',
|
||||
'182': ' ',
|
||||
'185': ' ',
|
||||
'200': '⛈️',
|
||||
'227': '🌨️',
|
||||
'230': '🌨️',
|
||||
'248': '☁️',
|
||||
'260': '☁️',
|
||||
'263': '🌧️',
|
||||
'266': '🌧️',
|
||||
'281': '🌧️',
|
||||
'284': '🌧️',
|
||||
'293': '🌧️',
|
||||
'296': '🌧️',
|
||||
'299': '🌧️',
|
||||
'302': '🌧️',
|
||||
'305': '🌧️',
|
||||
'308': '🌧️',
|
||||
'311': '🌧️',
|
||||
'314': '🌧️',
|
||||
'317': '🌧️',
|
||||
'320': '🌨️',
|
||||
'323': '🌨️',
|
||||
'326': '🌨️',
|
||||
'329': '❄️',
|
||||
'332': '❄️',
|
||||
'335': '❄️',
|
||||
'338': '❄️',
|
||||
'350': '🌧️',
|
||||
'353': '🌧️',
|
||||
'356': '🌧️',
|
||||
'359': '🌧️',
|
||||
'362': '🌧️',
|
||||
'365': '🌧️',
|
||||
'368': '🌧️',
|
||||
'371': '❄️',
|
||||
'374': '🌨️',
|
||||
'377': '🌨️',
|
||||
'386': '🌨️',
|
||||
'389': '🌨️',
|
||||
'392': '🌧️',
|
||||
'395': '❄️'
|
||||
}
|
||||
|
||||
data = {}
|
||||
|
||||
|
||||
weather = requests.get("https://wttr.in/Kohalpur?format=j1").json()
|
||||
|
||||
|
||||
def format_time(time):
|
||||
return time.replace("00", "").zfill(2)
|
||||
|
||||
|
||||
def format_temp(temp):
|
||||
return (hour['FeelsLikeC']+"°").ljust(3)
|
||||
|
||||
|
||||
def format_chances(hour):
|
||||
chances = {
|
||||
"chanceoffog": "Fog",
|
||||
"chanceoffrost": "Frost",
|
||||
"chanceofovercast": "Overcast",
|
||||
"chanceofrain": "Rain",
|
||||
"chanceofsnow": "Snow",
|
||||
"chanceofsunshine": "Sunshine",
|
||||
"chanceofthunder": "Thunder",
|
||||
"chanceofwindy": "Wind"
|
||||
}
|
||||
|
||||
conditions = []
|
||||
for event in chances.keys():
|
||||
if int(hour[event]) > 0:
|
||||
conditions.append(chances[event]+" "+hour[event]+"%")
|
||||
return ", ".join(conditions)
|
||||
|
||||
tempint = int(weather['current_condition'][0]['FeelsLikeC'])
|
||||
extrachar = ''
|
||||
if tempint > 0 and tempint < 10:
|
||||
extrachar = '+'
|
||||
|
||||
|
||||
data['text'] = ' '+WEATHER_CODES[weather['current_condition'][0]['weatherCode']] + \
|
||||
" "+extrachar+weather['current_condition'][0]['FeelsLikeC']+"°"
|
||||
|
||||
data['tooltip'] = f"<b>{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}°</b>\n"
|
||||
data['tooltip'] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}°\n"
|
||||
data['tooltip'] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n"
|
||||
data['tooltip'] += f"Humidity: {weather['current_condition'][0]['humidity']}%\n"
|
||||
for i, day in enumerate(weather['weather']):
|
||||
data['tooltip'] += f"\n<b>"
|
||||
if i == 0:
|
||||
data['tooltip'] += "Today, "
|
||||
if i == 1:
|
||||
data['tooltip'] += "Tomorrow, "
|
||||
data['tooltip'] += f"{day['date']}</b>\n"
|
||||
data['tooltip'] += f"⬆️{day['maxtempC']}° ⬇️{day['mintempC']}° "
|
||||
data['tooltip'] += f"🌅{day['astronomy'][0]['sunrise']} 🌇{day['astronomy'][0]['sunset']}\n"
|
||||
for hour in day['hourly']:
|
||||
if i == 0:
|
||||
if int(format_time(hour['time'])) < datetime.now().hour-2:
|
||||
continue
|
||||
data['tooltip'] += f"{format_time(hour['time'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeC'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n"
|
||||
|
||||
|
||||
print(json.dumps(data))
|
||||
Reference in new issue
Block a user