From 9f5b41c3e230cda406592167fcd0446a5f56821c Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Thu, 20 Feb 2025 22:52:34 +0900 Subject: updated wlogout.sh --- config/hypr/scripts/Wlogout.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config/hypr/scripts/Wlogout.sh b/config/hypr/scripts/Wlogout.sh index 7659008e..1f720b18 100755 --- a/config/hypr/scripts/Wlogout.sh +++ b/config/hypr/scripts/Wlogout.sh @@ -19,13 +19,16 @@ fi # Detect the current monitor's native resolution and scale monitor_info=$(hyprctl -j monitors | jq -r '.[] | select(.focused==true)') -# extract some info + resolution=$(echo "$monitor_info" | jq -r '.height') width=$(echo "$monitor_info" | jq -r '.width') hypr_scale=$(echo "$monitor_info" | jq -r '.scale') -# If hypr_scale >= 1.25 or resolution can't be detected, run wlogout with -b 3 -if [[ -z "$resolution" || ! "$resolution" =~ ^[0-9]+$ || -z "$hypr_scale" || $(awk "BEGIN {exit !($hypr_scale >= 1.25)}") -eq 1 ]]; then +# Round hypr_scale to 2 decimal places for accurate comparison +rounded_scale=$(echo "scale=2; $hypr_scale/1" | bc) + +# If resolution or scale is invalid or hypr_scale >= 1.25, run wlogout with -b 3 +if [[ -z "$resolution" || ! "$resolution" =~ ^[0-9]+$ || -z "$hypr_scale" || $(echo "$rounded_scale >= 1.25" | bc) -eq 1 ]]; then echo "Hypr_scale is greater than or equal to 1.25 or resolution could not be detected, running wlogout with -b 3" wlogout --protocol layer-shell -b 3 -T 100 -B 100 & exit 0 -- cgit v1.2.3 From 6c96baddd16accffb27cad48d534cf688e83d332 Mon Sep 17 00:00:00 2001 From: brockar Date: Fri, 21 Feb 2025 16:32:04 -0300 Subject: Weather.py update, auto get location I just can test it on my location, so I need that be tested before merging :) --- config/hypr/UserScripts/Weather.py | 61 +++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/config/hypr/UserScripts/Weather.py b/config/hypr/UserScripts/Weather.py index e3a6c538..c739d2c5 100755 --- a/config/hypr/UserScripts/Weather.py +++ b/config/hypr/UserScripts/Weather.py @@ -1,13 +1,22 @@ #!/usr/bin/env python3 # /* ---- šŸ’« https://github.com/JaKooLit šŸ’« ---- */ # +# original code https://gist.github.com/Surendrajat/ff3876fd2166dd86fb71180f4e9342d7 # weather using python -import subprocess -from pyquery import PyQuery # install using `pip install pyquery` +import requests import json import os +from pyquery import PyQuery # install using `pip install pyquery` + + +# Get current location based on IP address +def get_location(): + response = requests.get("https://ipinfo.io") + data = response.json() + loc = data["loc"].split(",") + return float(loc[0]), float(loc[1]) + -# original code https://gist.github.com/Surendrajat/ff3876fd2166dd86fb71180f4e9342d7 # weather icons weather_icons = { "sunnyDay": "󰖙", @@ -22,30 +31,22 @@ weather_icons = { "default": "īŒ‚", } -# get location_id -# to get your own location_id, go to https://weather.com & search your location. -# once you choose your location, you can see the location_id in the URL(64 chars long hex string) -# like this: https://weather.com/en-PH/weather/today/l/bca47d1099e762a012b9a139c36f30a0b1e647f69c0c4ac28b537e7ae9c1c200 -location_id = "bca47d1099e762a012b9a139c36f30a0b1e647f69c0c4ac28b537e7ae9c1c200" # TODO +# Get latitude and longitude +latitude, longitude = get_location() -# NOTE to change to deg F, change the URL to your preffered location after weather.com -# Default is English-Philippines with Busan, South Korea as location_id -# get html page -url = "https://weather.com/en-PH/weather/today/l/" + location_id +# Open-Meteo API endpoint +url = f"https://weather.com/en-PH/weather/today/l/{latitude},{longitude}" html_data = PyQuery(url=url) # current temperature temp = html_data("span[data-testid='TemperatureValue']").eq(0).text() -# print(temp) # current status phrase status = html_data("div[data-testid='wxPhrase']").text() status = f"{status[:16]}.." if len(status) > 17 else status -# print(status) # status code status_code = html_data("#regionHeader").attr("class").split(" ")[2].split("-")[2] -# print(status_code) # status icon icon = ( @@ -53,14 +54,12 @@ icon = ( if status_code in weather_icons else weather_icons["default"] ) -# print(icon) # temperature feels like temp_feel = html_data( "div[data-testid='FeelsLikeSection'] > span > span[data-testid='TemperatureValue']" ).text() temp_feel_text = f"Feels like {temp_feel}c" -# print(temp_feel_text) # min-max temperature temp_min = ( @@ -74,26 +73,21 @@ temp_max = ( .text() ) temp_min_max = f"ļ‹‹ {temp_min}\t\t {temp_max}" -# print(temp_min_max) # wind speed wind_speed = html_data("span[data-testid='Wind']").text().split("\n")[1] wind_text = f" {wind_speed}" -# print(wind_text) # humidity humidity = html_data("span[data-testid='PercentageValue']").text() humidity_text = f"ī³ {humidity}" -# print(humidity_text) # visibility -visbility = html_data("span[data-testid='VisibilityValue']").text() -visbility_text = f" {visbility}" -# print(visbility_text) +visibility = html_data("span[data-testid='VisibilityValue']").text() +visibility_text = f" {visibility}" # air quality index air_quality_index = html_data("text[data-testid='DonutChartValue']").text() -# print(air_quality_index) # hourly rain prediction prediction = html_data("section[aria-label='Hourly Forecast']")( @@ -101,7 +95,6 @@ prediction = html_data("section[aria-label='Hourly Forecast']")( ).text() prediction = prediction.replace("Chance of Rain", "") prediction = f"\n\n (hourly) {prediction}" if len(prediction) > 0 else prediction -# print(prediction) # tooltip text tooltip_text = str.format( @@ -112,7 +105,7 @@ tooltip_text = str.format( f"{temp_feel_text}", f"{temp_min_max}", f"{wind_text}\t{humidity_text}", - f"{visbility_text}\tAQI {air_quality_index}", + f"{visibility_text}\tAQI {air_quality_index}", f" {prediction}", ) @@ -125,14 +118,16 @@ out_data = { } print(json.dumps(out_data)) -simple_weather =f"{icon} {status}\n" + \ - f" {temp} ({temp_feel_text})\n" + \ - f"{wind_text} \n" + \ - f"{humidity_text} \n" + \ - f"{visbility_text} AQI{air_quality_index}\n" +simple_weather = ( + f"{icon} {status}\n" + + f" {temp} ({temp_feel_text})\n" + + f"{wind_text} \n" + + f"{humidity_text} \n" + + f"{visibility_text} AQI{air_quality_index}\n" +) try: with open(os.path.expanduser("~/.cache/.weather_cache"), "w") as file: file.write(simple_weather) -except: - pass +except Exception as e: + print(f"Error writing to cache: {e}") -- cgit v1.2.3 From 341cdff88a33007724b59018d486363eda4c22c9 Mon Sep 17 00:00:00 2001 From: "Ja.KooLit" <85185940+JaKooLit@users.noreply.github.com> Date: Sat, 22 Feb 2025 10:22:19 +0900 Subject: Update Weather.py just added the manual addition of location in case user wants that --- config/hypr/UserScripts/Weather.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/config/hypr/UserScripts/Weather.py b/config/hypr/UserScripts/Weather.py index c739d2c5..b9efe4e4 100755 --- a/config/hypr/UserScripts/Weather.py +++ b/config/hypr/UserScripts/Weather.py @@ -8,15 +8,6 @@ import json import os from pyquery import PyQuery # install using `pip install pyquery` - -# Get current location based on IP address -def get_location(): - response = requests.get("https://ipinfo.io") - data = response.json() - loc = data["loc"].split(",") - return float(loc[0]), float(loc[1]) - - # weather icons weather_icons = { "sunnyDay": "󰖙", @@ -31,11 +22,31 @@ weather_icons = { "default": "īŒ‚", } +# Get current location based on IP address +def get_location(): + response = requests.get("https://ipinfo.io") + data = response.json() + loc = data["loc"].split(",") + return float(loc[0]), float(loc[1]) + # Get latitude and longitude latitude, longitude = get_location() # Open-Meteo API endpoint url = f"https://weather.com/en-PH/weather/today/l/{latitude},{longitude}" + +# manual location_id +# NOTE: if you want to add manually, make sure you disable def get_location above +# to get your own location_id, go to https://weather.com & search your location. +# once you choose your location, you can see the location_id in the URL(64 chars long hex string) +# like this: https://weather.com/en-PH/weather/today/l/bca47d1099e762a012b9a139c36f30a0b1e647f69c0c4ac28b537e7ae9c1c200 +#location_id = "bca47d1099e762a012b9a139c36f30a0b1e647f69c0c4ac28b537e7ae9c1c200" # TODO + +# NOTE to change to deg F, change the URL to your preffered location after weather.com +# Default is English-Philippines with Busan, South Korea as location_id +# get html page +#url = "https://weather.com/en-PH/weather/today/l/" + location_id + html_data = PyQuery(url=url) # current temperature -- cgit v1.2.3