diff options
| author | subh <subh@subh.space> | 2026-03-31 07:35:08 +0530 |
|---|---|---|
| committer | subh <subh@subh.space> | 2026-03-31 07:35:08 +0530 |
| commit | 0203dd4b8d45c663356f797c11be17fdec6f22f2 (patch) | |
| tree | 7d214feb3205b9bba80b5510e41191891aa59aeb /scripts/weather.py | |
| parent | 218e74f316f248b090659fc79b3f96fc7b302db8 (diff) | |
changed the weather module for quickshell
Diffstat (limited to 'scripts/weather.py')
| -rwxr-xr-x | scripts/weather.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/scripts/weather.py b/scripts/weather.py new file mode 100755 index 0000000..0c2af7b --- /dev/null +++ b/scripts/weather.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import requests +import os +import json +from dotenv import load_dotenv + +def getWeatherIcon(isDayTime: bool, weatherDescription: str): + if weatherDescription in ["CLEAR", "MOSTLY_CLEAR"]: + if isDayTime: + return " " + else: + return " " + if weatherDescription in ["PARTLY_CLOUDY"]: + if isDayTime: + return " " + else: + return " " + if weatherDescription in ["CLOUDY", "MOSTLY_CLOUDY"]: + return " " + if weatherDescription in ["LIGHT_RAIN", "LIGHT_TO_MODERATE_RAIN","LIGHT_RAIN_SHOWERS"]: + if isDayTime: + return " " + else: + return " " + if weatherDescription in ["RAIN", "RAIN_SHOWERS", "HEAVY_RAIN", "HEAVY_RAIN_SHOWERS", "MODERATE_TO_HEAVY_RAIN", "RAIN_PERIODICALLY_HEAVY"]: + return " " + if weatherDescription in ["SNOW", "LIGHT_SNOW", "HEAVY_SNOW", "SNOW_SHOWERS", "LIGHT_SNOW_SHOWERS", "HEAVY_SNOW_SHOWERS", "SNOWSTORM", "BLOWING_SNOW", "RAIN_AND_SNOW", "HAIL"]: + return " " + if weatherDescription in ["LIGHT_THUNDERSTORM_RAIN"]: + if isDayTime: + return " " + else: + return " " + + if weatherDescription in ["THUNDERSHOWER", "SCATTERED_THUNDERSTORMS", "THUNDERSTORM", "HEAVY_THUNDERSTORM"]: + return " " + + if weatherDescription in ["WINDY"]: + if isDayTime: + return " " + else: + return " " + + if weatherDescription in ["FOG","HAZE","DUST","MIST","SMOKE"]: + if isDay: + return " " + else: + return " " + + return " " + + +url = "https://weather.googleapis.com/v1/currentConditions:lookup" +lat = "25.4448" +long = "81.8432" + +load_dotenv() +params = { + "key":os.getenv("API_KEY"), + "location.latitude":lat, + "location.longitude": long + } + + +response = requests.get(url, params=params) +jsonDump = json.loads(response.text) +currentTemperature = jsonDump["temperature"]["degrees"] +weatherDescription = jsonDump["weatherCondition"]["type"] +isDaytime = jsonDump["isDaytime"] +precipitation = jsonDump["precipitation"]["probability"]["percent"] + + +weatherIcon = getWeatherIcon(isDaytime, weatherDescription) +print(weatherIcon, f"{currentTemperature}°C",f" {precipitation}%") + |
