mirror of
				https://github.com/assenzostefano/RetniNet.git
				synced 2025-06-05 21:49:14 +02:00 
			
		
		
		
	Add translate for command meteo and comments on the code
This commit is contained in:
		
							
								
								
									
										44
									
								
								index.py
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								index.py
									
									
									
									
									
								
							| @@ -16,6 +16,8 @@ import json | |||||||
| import goslate | import goslate | ||||||
| import urllib.request | import urllib.request | ||||||
| import urllib.parse | import urllib.parse | ||||||
|  | import logging | ||||||
|  | import deepl | ||||||
| from dotenv import load_dotenv | from dotenv import load_dotenv | ||||||
| from yt_dlp import YoutubeDL | from yt_dlp import YoutubeDL | ||||||
| from platform import system | from platform import system | ||||||
| @@ -83,14 +85,19 @@ def meteo(pm): | |||||||
|     bot.register_next_step_handler(sent_msg, meteo_step) |     bot.register_next_step_handler(sent_msg, meteo_step) | ||||||
|  |  | ||||||
| def meteo_step(message): | def meteo_step(message): | ||||||
|  |     translator = deepl.Translator(os.getenv('DEEPL_TOKEN')) | ||||||
|  |     result = translator.translate_text('hi', target_lang='IT')  | ||||||
|  |     translated_text = result.text | ||||||
|     city = message.text |     city = message.text | ||||||
|     token_weather = os.environ.get('WEATHER_TOKEN') |     token_weather = os.environ.get('WEATHER_TOKEN') | ||||||
|     response = requests.get("https://api.openweathermap.org/data/2.5/weather?q="+city+",it&APPID="+token_weather).json() |     response = requests.get("https://api.openweathermap.org/data/2.5/weather?q="+city+",it&APPID="+token_weather).json() | ||||||
|     weather = response['weather'][0]['main'] |     weather = response['weather'][0]['main'] # | ||||||
|     temp = response['main']['temp'] |     temp = response['main']['temp'] | ||||||
|     temp = temp - 273.15 |     temp = temp - 273.15 | ||||||
|  |     weather_translate = translator.translate_text(weather, target_lang='IT') | ||||||
|  |     result_weather = weather_translate.text | ||||||
|     bot.send_message(message.chat.id, "🌡️ La temperatura in " + city + " è di " + str(temp) + "°C") |     bot.send_message(message.chat.id, "🌡️ La temperatura in " + city + " è di " + str(temp) + "°C") | ||||||
|     bot.send_message(message.chat.id, "🌧️ La condizione è " + weather) |     bot.send_message(message.chat.id, "🌧️ La condizione è " + result_weather) | ||||||
|  |  | ||||||
| #Command /stats | #Command /stats | ||||||
| @bot.message_handler(commands=['stats']) | @bot.message_handler(commands=['stats']) | ||||||
| @@ -143,27 +150,50 @@ def epicgames(message): | |||||||
| def epicgames_step(message): | def epicgames_step(message): | ||||||
|     text = message.text |     text = message.text | ||||||
|     if text == 'disponibile': |     if text == 'disponibile': | ||||||
|         print("Triggered command EPICGAMES.") |         print("Triggered command EPICGAMES DISPONIBILE.") | ||||||
|  |         #URL API | ||||||
|         url = "https://api.plenusbot.xyz/epic_games?country=IT" |         url = "https://api.plenusbot.xyz/epic_games?country=IT" | ||||||
|         response = requests.get(url).json() |         response = requests.get(url).json() | ||||||
|  |         #Title of current games | ||||||
|         current_games = response['currentGames'][0]['title'] |         current_games = response['currentGames'][0]['title'] | ||||||
|  |         #Image current games | ||||||
|         image_currentgames = response['currentGames'][0]['keyImages'][0]['url'] |         image_currentgames = response['currentGames'][0]['keyImages'][0]['url'] | ||||||
|  |         #Description current games | ||||||
|         current_games_description = response['currentGames'][0]['description'] |         current_games_description = response['currentGames'][0]['description'] | ||||||
|  |         #Token for translate | ||||||
|  |         translator = deepl.Translator(os.getenv('DEEPL_TOKEN')) | ||||||
|  |         #Translate description current games | ||||||
|  |         description_translate = translator.translate_text(current_games_description, target_lang='IT') | ||||||
|  |         result_description = description_translate.text | ||||||
|         send_img = bot.send_photo(message.chat.id, image_currentgames) |         send_img = bot.send_photo(message.chat.id, image_currentgames) | ||||||
|         sent_msg = bot.send_message(message.chat.id, "🎮 Il gioco gratis di oggi è " + current_games + "\n\n" + current_games_description) |         sent_msg = bot.send_message(message.chat.id, "🎮 Il gioco gratis di oggi è " + current_games + "\n\n" + result_description) | ||||||
|     else: |     else: | ||||||
|  |         print("Triggered command EPICGAMES FUTURO.") | ||||||
|  |         #URL API | ||||||
|         url = "https://api.plenusbot.xyz/epic_games?country=IT" |         url = "https://api.plenusbot.xyz/epic_games?country=IT" | ||||||
|         response = requests.get(url).json() |         response = requests.get(url).json() | ||||||
|  |         #Title of future games | ||||||
|         future_games1 = response['nextGames'][0]['title'] |         future_games1 = response['nextGames'][0]['title'] | ||||||
|  |         #Image future games | ||||||
|         image_futuregames1 = response['nextGames'][0]['keyImages'][0]['url'] |         image_futuregames1 = response['nextGames'][0]['keyImages'][0]['url'] | ||||||
|  |         #Description future games | ||||||
|         future_games_description1 = response['nextGames'][0]['description'] |         future_games_description1 = response['nextGames'][0]['description'] | ||||||
|  |         #Token for translate | ||||||
|  |         translator = deepl.Translator(os.getenv('DEEPL_TOKEN')) | ||||||
|  |         description_translate1 = translator.translate_text(future_games_description1, target_lang='IT') | ||||||
|  |         result_description1 = description_translate1.text | ||||||
|         send_img = bot.send_photo(message.chat.id, image_futuregames1) |         send_img = bot.send_photo(message.chat.id, image_futuregames1) | ||||||
|         sent_msg = bot.send_message(message.chat.id, "🎮 Il gioco futuro è " + future_games1 + "\n\n" + future_games_description1) |         sent_msg = bot.send_message(message.chat.id, "🎮 Il gioco futuro è " + future_games1 + "\n\n" + result_description1) | ||||||
|  |         #Title of future games | ||||||
|         future_games2 = response['nextGames'][1]['title'] |         future_games2 = response['nextGames'][1]['title'] | ||||||
|  |         #Image future games | ||||||
|         image_futuregames2 = response['nextGames'][1]['keyImages'][0]['url'] |         image_futuregames2 = response['nextGames'][1]['keyImages'][0]['url'] | ||||||
|  |         #Description future games | ||||||
|         future_games_description2 = response['nextGames'][1]['description'] |         future_games_description2 = response['nextGames'][1]['description'] | ||||||
|  |         #Traslate description future games | ||||||
|  |         description_translate2 = translator.translate_text(future_games_description2, target_lang='IT') | ||||||
|  |         result_description2 = description_translate2.text | ||||||
|         send_img = bot.send_photo(message.chat.id, image_futuregames2) |         send_img = bot.send_photo(message.chat.id, image_futuregames2) | ||||||
|         sent_msg = bot.send_message(message.chat.id, "🎮 Il gioco futuro è " + future_games2 + "\n\n" + future_games_description2) |         sent_msg = bot.send_message(message.chat.id, "🎮 Il gioco futuro è " + future_games2 + "\n\n" + result_description2) | ||||||
|  |  | ||||||
|  |  | ||||||
| bot.polling() | bot.polling() | ||||||
| @@ -1,40 +1,30 @@ | |||||||
| # Automatically generated by https://github.com/damnever/pigar. |  | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 29 |  | ||||||
| bs4 == 0.0.1 | bs4 == 0.0.1 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 17 | deepl == 1.8.0 | ||||||
|  |  | ||||||
| goslate == 1.5.4 | goslate == 1.5.4 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 26 |  | ||||||
| jmespath == 1.0.0 | jmespath == 1.0.0 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 1 |  | ||||||
| psutil == 5.9.1 | psutil == 5.9.1 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 3 |  | ||||||
| pyfiglet == 0.8.post1 | pyfiglet == 0.8.post1 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 20 |  | ||||||
| python_dotenv == 0.20.0 | python_dotenv == 0.20.0 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 10 |  | ||||||
| python_ffmpeg == 1.0.14 | python_ffmpeg == 1.0.14 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 13 |  | ||||||
| python_weather == 0.3.7 | python_weather == 0.3.7 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 28 |  | ||||||
| pytube == 12.1.0 | pytube == 12.1.0 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 12,15 | requests == 2.25.1 | ||||||
| requests == 2.28.0 |  | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 27 |  | ||||||
| telebot == 0.0.4 | telebot == 0.0.4 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 23 |  | ||||||
| tqdm == 4.64.0 | tqdm == 4.64.0 | ||||||
|  |  | ||||||
| # D:\Progetti Github\RetniNet\index.py: 21 |  | ||||||
| yt_dlp == 2022.5.18 | yt_dlp == 2022.5.18 | ||||||
|  |  | ||||||
|  | pytelegrambotapi == 4.5.1 | ||||||
		Reference in New Issue
	
	Block a user