From 1abccd1661cda3b14a4fd3364070123b5b6f5437 Mon Sep 17 00:00:00 2001 From: stef-devs Date: Mon, 20 Jun 2022 09:35:44 +0200 Subject: [PATCH] Add translate for command meteo and comments on the code --- index.py | 44 +++++++++++++++++++++++++++++++++++++------- requirements.txt | 20 +++++--------------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/index.py b/index.py index 5cb9075..09d7887 100644 --- a/index.py +++ b/index.py @@ -16,6 +16,8 @@ import json import goslate import urllib.request import urllib.parse +import logging +import deepl from dotenv import load_dotenv from yt_dlp import YoutubeDL from platform import system @@ -83,14 +85,19 @@ def meteo(pm): bot.register_next_step_handler(sent_msg, meteo_step) 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 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() - weather = response['weather'][0]['main'] + weather = response['weather'][0]['main'] # temp = response['main']['temp'] 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 condizione è " + weather) + bot.send_message(message.chat.id, "🌧️ La condizione è " + result_weather) #Command /stats @bot.message_handler(commands=['stats']) @@ -143,27 +150,50 @@ def epicgames(message): def epicgames_step(message): text = message.text if text == 'disponibile': - print("Triggered command EPICGAMES.") + print("Triggered command EPICGAMES DISPONIBILE.") + #URL API url = "https://api.plenusbot.xyz/epic_games?country=IT" response = requests.get(url).json() + #Title of current games current_games = response['currentGames'][0]['title'] + #Image current games image_currentgames = response['currentGames'][0]['keyImages'][0]['url'] + #Description current games 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) - 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: + print("Triggered command EPICGAMES FUTURO.") + #URL API url = "https://api.plenusbot.xyz/epic_games?country=IT" response = requests.get(url).json() + #Title of future games future_games1 = response['nextGames'][0]['title'] + #Image future games image_futuregames1 = response['nextGames'][0]['keyImages'][0]['url'] + #Description future games 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) - 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'] + #Image future games image_futuregames2 = response['nextGames'][1]['keyImages'][0]['url'] + #Description future games 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) - 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() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e37656c..e33ff63 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,40 +1,30 @@ -# Automatically generated by https://github.com/damnever/pigar. -# D:\Progetti Github\RetniNet\index.py: 29 bs4 == 0.0.1 -# D:\Progetti Github\RetniNet\index.py: 17 +deepl == 1.8.0 + goslate == 1.5.4 -# D:\Progetti Github\RetniNet\index.py: 26 jmespath == 1.0.0 -# D:\Progetti Github\RetniNet\index.py: 1 psutil == 5.9.1 -# D:\Progetti Github\RetniNet\index.py: 3 pyfiglet == 0.8.post1 -# D:\Progetti Github\RetniNet\index.py: 20 python_dotenv == 0.20.0 -# D:\Progetti Github\RetniNet\index.py: 10 python_ffmpeg == 1.0.14 -# D:\Progetti Github\RetniNet\index.py: 13 python_weather == 0.3.7 -# D:\Progetti Github\RetniNet\index.py: 28 pytube == 12.1.0 -# D:\Progetti Github\RetniNet\index.py: 12,15 -requests == 2.28.0 +requests == 2.25.1 -# D:\Progetti Github\RetniNet\index.py: 27 telebot == 0.0.4 -# D:\Progetti Github\RetniNet\index.py: 23 tqdm == 4.64.0 -# D:\Progetti Github\RetniNet\index.py: 21 yt_dlp == 2022.5.18 + +pytelegrambotapi == 4.5.1 \ No newline at end of file