Add snow emoji for precipitation when it's snowing
Also added dict for all emojis
This commit is contained in:
		
							parent
							
								
									fbb2c65fd0
								
							
						
					
					
						commit
						f5c7bf8e9e
					
				
					 1 changed files with 27 additions and 11 deletions
				
			
		| 
						 | 
					@ -8,6 +8,8 @@ from exceptions import ServerCommunicationError, NoArgError, WeatherStationNotFo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
token: str
 | 
					token: str
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EMOJIS = {'feels_like': '🧑', 'rain': '☔', 'snow': '🌨️', 'wind': '💨', 'sun': '☀️'}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def __init__():
 | 
					def __init__():
 | 
				
			||||||
    with open("openweathermap_token") as openweathermap_token:
 | 
					    with open("openweathermap_token") as openweathermap_token:
 | 
				
			||||||
| 
						 | 
					@ -39,12 +41,16 @@ class CurrentWeather:
 | 
				
			||||||
        self.description = json_data['weather'][0]['description']
 | 
					        self.description = json_data['weather'][0]['description']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        string = f"*Now*: {self.main} | {self.temperature:.0f}°C 🧑: {self.feels_like:.0f}°C"
 | 
					        string = f"*Now*: {self.main} | {self.temperature:.0f}°C {EMOJIS['feels_like']}: {self.feels_like:.0f}°C "
 | 
				
			||||||
        if self.rain != -1:
 | 
					        if self.rain != -1:
 | 
				
			||||||
            string += f" ☔: {self.rain:.0f}mm"
 | 
					            if self.main == 'Snow':
 | 
				
			||||||
 | 
					                string += EMOJIS['snow']
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                string += EMOJIS['rain']
 | 
				
			||||||
 | 
					            string += f": {self.rain:.0f}mm"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        string += f" 💨: {3.6 * self.wind_speed:.1f}km/h" \
 | 
					        string += f" {EMOJIS['wind']}: {3.6 * self.wind_speed:.1f}km/h" \
 | 
				
			||||||
                  f" ☀️: {self.sunrise.strftime('%H:%M')} - {self.sunset.strftime('%H:%M')}"
 | 
					                  f" {EMOJIS['sun']}: {self.sunrise.strftime('%H:%M')} - {self.sunset.strftime('%H:%M')}"
 | 
				
			||||||
        return string
 | 
					        return string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -72,11 +78,16 @@ class HourlyWeather:
 | 
				
			||||||
        self.description = json_data['weather'][0]['description']
 | 
					        self.description = json_data['weather'][0]['description']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        string = f"*{self.time.strftime('%Hh')}*: {self.main} | {self.temperature:.0f}°C 🧑: {self.feels_like:.0f}°C"
 | 
					        string = f"*{self.time.strftime('%Hh')}*: {self.main} | {self.temperature:.0f}°C" \
 | 
				
			||||||
 | 
					                 f" {EMOJIS['feels_like']}: {self.feels_like:.0f}°C "
 | 
				
			||||||
        if self.probability_of_precipitation != 0:
 | 
					        if self.probability_of_precipitation != 0:
 | 
				
			||||||
            string += f" ☔: {100 * self.probability_of_precipitation:.0f}% {self.rain}mm"
 | 
					            if self.main == 'Snow':
 | 
				
			||||||
 | 
					                string += EMOJIS['snow']
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                string += EMOJIS['rain']
 | 
				
			||||||
 | 
					            string += f": {100 * self.probability_of_precipitation:.0f}% {self.rain}mm"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        string += f" 💨: {3.6 * self.wind_speed:.1f}km/h"
 | 
					        string += f" {EMOJIS['wind']}: {3.6 * self.wind_speed:.1f}km/h"
 | 
				
			||||||
        return string
 | 
					        return string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,10 +116,14 @@ class DailyWeather:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        string = f"*{self.time.strftime('%d')}*: {self.main} | {self.temp['min']:.0f}°C - {self.temp['day']:.0f}°C" \
 | 
					        string = f"*{self.time.strftime('%d')}*: {self.main} | {self.temp['min']:.0f}°C - {self.temp['day']:.0f}°C" \
 | 
				
			||||||
                 f" - {self.temp['max']:.0f}°C 🧑: {self.feels_like:.0f}°C"
 | 
					                 f" - {self.temp['max']:.0f}°C {EMOJIS['feels_like']}: {self.feels_like:.0f}°C "
 | 
				
			||||||
        if self.probability_of_precipitation != 0:
 | 
					        if self.probability_of_precipitation != 0:
 | 
				
			||||||
            string += f" ☔: {100 * self.probability_of_precipitation:.0f}% {self.rain}mm"
 | 
					            if self.main == 'Snow':
 | 
				
			||||||
        string += f" 💨: {3.6 * self.wind_speed:.1f}km/h"
 | 
					                string += EMOJIS['snow']
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                string += EMOJIS['rain']
 | 
				
			||||||
 | 
					            string += f": {100 * self.probability_of_precipitation:.0f}% {self.rain}mm"
 | 
				
			||||||
 | 
					        string += f" {EMOJIS['wind']}: {3.6 * self.wind_speed:.1f}km/h"
 | 
				
			||||||
        return string
 | 
					        return string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -221,6 +236,7 @@ def handle_weather(update, context):
 | 
				
			||||||
    if requested_city.name == "none":
 | 
					    if requested_city.name == "none":
 | 
				
			||||||
        raise WeatherStationNotFoundError
 | 
					        raise WeatherStationNotFoundError
 | 
				
			||||||
    requested_city.query_weather()
 | 
					    requested_city.query_weather()
 | 
				
			||||||
    update.message.reply_text(requested_city.get_weather_str(), disable_notification=True, parse_mode=ParseMode.MARKDOWN)
 | 
					    update.message.reply_text(requested_city.get_weather_str(), disable_notification=True,
 | 
				
			||||||
 | 
					                              parse_mode=ParseMode.MARKDOWN)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    requested_city.weather.clear()
 | 
					    requested_city.weather.clear()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue