Add translate.py

This commit is contained in:
neppa 2023-10-08 16:36:44 -04:00
parent 798a54f429
commit 8224c58da1

29
translate.py Normal file
View file

@ -0,0 +1,29 @@
import os
from googletrans import Translator
from twitch_chat_irc import twitch_chat_irc
from dotenv import load_dotenv
channel_to_read_chat_from = ""
channel_to_send_translations_to = ""
load_dotenv()
username = os.getenv('TWITCH_LOGIN_NAME')
oauth = os.getenv('TWITCH_OAUTH_TOKEN')
connection = twitch_chat_irc.TwitchChatIRC()
connection = twitch_chat_irc.TwitchChatIRC(username, oauth)
translator = Translator()
def do_something(message):
msg = message["message"]
translated_text = translator.translate(msg)
print(translated_text)
translated = translated_text.text
connection.send(channel_to_read_chat_from, f"{message['display-name']}: {translated}")
connection.listen(channel_to_send_translations_to, on_message=do_something)