#!/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"]: if isDayTime: return "โ˜€๏ธ" else: return "๐ŸŒ™ " if weatherDescription in ["PARTLY_CLOUDY", "MOSTLY_CLEAR"]: 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 = "" long = "" 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"] windSpeed = jsonDump["wind"]["speed"]["value"] weatherIcon = getWeatherIcon(isDaytime, weatherDescription) print(weatherIcon, f"{currentTemperature}ยฐC",f"โ˜” {precipitation}%", f"๐ŸŒฌ๏ธ {windSpeed}kph")