From d7ff1c1dea16619a38f35536a5c00685d848abce Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Fri, 10 May 2024 02:03:31 +0900 Subject: Initial Push - Moving to Wallust from Pywal --- config/hypr/UserScripts/Weather.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'config/hypr/UserScripts/Weather.py') diff --git a/config/hypr/UserScripts/Weather.py b/config/hypr/UserScripts/Weather.py index 046dbcd3..7b23d28d 100755 --- a/config/hypr/UserScripts/Weather.py +++ b/config/hypr/UserScripts/Weather.py @@ -76,7 +76,7 @@ temp_min_max = f" {temp_min}\t\t {temp_max}" # wind speed wind_speed = html_data("span[data-testid='Wind']").text().split("\n")[1] -wind_text = f"煮 {wind_speed}" +wind_text = f" {wind_speed}" # print(wind_text) # humidity @@ -86,7 +86,7 @@ humidity_text = f" {humidity}" # visibility visbility = html_data("span[data-testid='VisibilityValue']").text() -visbility_text = f" {visbility}" +visbility_text = f" {visbility}" # print(visbility_text) # air quality index @@ -127,7 +127,7 @@ 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" + f"{visbility_text} AQI{air_quality_index}\n" try: with open(os.path.expanduser("~/.cache/.weather_cache"), "w") as file: -- cgit v1.2.3 From 56810d5996c38f12742c4c147f61efe056ac12bb Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Fri, 10 May 2024 20:30:39 +0900 Subject: weather.py alignment adjustment --- config/hypr/UserScripts/Weather.py | 135 +++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) (limited to 'config/hypr/UserScripts/Weather.py') diff --git a/config/hypr/UserScripts/Weather.py b/config/hypr/UserScripts/Weather.py index 7b23d28d..9f9c1440 100755 --- a/config/hypr/UserScripts/Weather.py +++ b/config/hypr/UserScripts/Weather.py @@ -53,6 +53,66 @@ icon = ( ) # 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)#!/usr/bin/env python3 + +import subprocess +from pyquery import PyQuery # install using `pip install pyquery` +import json +import os + +# original code https://gist.github.com/Surendrajat/ff3876fd2166dd86fb71180f4e9342d7 +# weather icons +weather_icons = { + "sunnyDay": "", + "clearNight": "", + "cloudyFoggyDay": "", + "cloudyFoggyNight": "", + "rainyDay": "", + "rainyNight": "", + "snowyIcyDay": "", + "snowyIcyNight": "", + "severe": "", + "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 + +# 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 +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 = ( + weather_icons[status_code] + 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']" @@ -60,6 +120,81 @@ temp_feel = html_data( temp_feel_text = f"Feels like {temp_feel}c" # print(temp_feel_text) +# min-max temperature +temp_min = ( + html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']") + .eq(0) + .text() +) +temp_max = ( + html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']") + .eq(1) + .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) + +# 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']")( + "div[data-testid='SegmentPrecipPercentage'] > span" +).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( + "\t\t{}\t\t\n{}\n{}\n{}\n\n{}\n{}\n{}{}", + f'{temp}', + f" {icon}", + f"{status}", + f"{temp_feel_text}", + f"{temp_min_max}", + f"{wind_text}\t{humidity_text}", + f"{visbility_text}\tAQI {air_quality_index}", + f" {prediction}", +) + +# print waybar module data +out_data = { + "text": f"{icon} {temp}", + "alt": status, + "tooltip": tooltip_text, + "class": status_code, +} +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" + +try: + with open(os.path.expanduser("~/.cache/.weather_cache"), "w") as file: + file.write(simple_weather) +except: + pass + # min-max temperature temp_min = ( html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']") -- cgit v1.2.3 From 5b85fd7415ad55b3323cd1caacf1ae86c4b3a6ea Mon Sep 17 00:00:00 2001 From: JaKooLit Date: Sun, 12 May 2024 02:17:58 -0400 Subject: Weather.py clean up. Double codes --- config/hypr/UserScripts/Weather.py | 147 ++----------------------------------- 1 file changed, 6 insertions(+), 141 deletions(-) (limited to 'config/hypr/UserScripts/Weather.py') diff --git a/config/hypr/UserScripts/Weather.py b/config/hypr/UserScripts/Weather.py index 9f9c1440..5cd11a66 100755 --- a/config/hypr/UserScripts/Weather.py +++ b/config/hypr/UserScripts/Weather.py @@ -53,66 +53,6 @@ icon = ( ) # 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)#!/usr/bin/env python3 - -import subprocess -from pyquery import PyQuery # install using `pip install pyquery` -import json -import os - -# original code https://gist.github.com/Surendrajat/ff3876fd2166dd86fb71180f4e9342d7 -# weather icons -weather_icons = { - "sunnyDay": "", - "clearNight": "", - "cloudyFoggyDay": "", - "cloudyFoggyNight": "", - "rainyDay": "", - "rainyNight": "", - "snowyIcyDay": "", - "snowyIcyNight": "", - "severe": "", - "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 - -# 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 -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 = ( - weather_icons[status_code] - 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']" @@ -120,81 +60,6 @@ temp_feel = html_data( temp_feel_text = f"Feels like {temp_feel}c" # print(temp_feel_text) -# min-max temperature -temp_min = ( - html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']") - .eq(0) - .text() -) -temp_max = ( - html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']") - .eq(1) - .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) - -# 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']")( - "div[data-testid='SegmentPrecipPercentage'] > span" -).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( - "\t\t{}\t\t\n{}\n{}\n{}\n\n{}\n{}\n{}{}", - f'{temp}', - f" {icon}", - f"{status}", - f"{temp_feel_text}", - f"{temp_min_max}", - f"{wind_text}\t{humidity_text}", - f"{visbility_text}\tAQI {air_quality_index}", - f" {prediction}", -) - -# print waybar module data -out_data = { - "text": f"{icon} {temp}", - "alt": status, - "tooltip": tooltip_text, - "class": status_code, -} -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" - -try: - with open(os.path.expanduser("~/.cache/.weather_cache"), "w") as file: - file.write(simple_weather) -except: - pass - # min-max temperature temp_min = ( html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']") @@ -221,7 +86,7 @@ humidity_text = f" {humidity}" # visibility visbility = html_data("span[data-testid='VisibilityValue']").text() -visbility_text = f" {visbility}" +visbility_text = f" {visbility}" # print(visbility_text) # air quality index @@ -258,14 +123,14 @@ out_data = { } print(json.dumps(out_data)) -simple_weather =f"{icon} {status}\n" + \ +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" + f"{wind_text} \n" + \ + f"{humidity_text} \n" + \ + f"{visbility_text} AQI{air_quality_index}\n" try: with open(os.path.expanduser("~/.cache/.weather_cache"), "w") as file: file.write(simple_weather) except: - pass \ No newline at end of file + pass -- cgit v1.2.3