import os
import signal
import sys
import argparse
import json
import time
import pprint
import random
import requests
import datetime
import glob
import threading 
# import keyboard 
from pynput import keyboard
from threading import Thread, Semaphore
from streamlink import Streamlink
from fake_useragent import UserAgent
from rich.console import Console
from rich.live import Live
from rich.prompt import Prompt
from rich.spinner import Spinner
from rich.table import Table
from rich.text import Text
import subprocess
import pty





console = Console()


def hprint(color, texte):
    timestamp = datetime.datetime.now().strftime("%Hh %Mm %Ss")
    console.print("[bold "+color+"] ["+timestamp+"] "+texte+" [/bold "+color+"]")


def del_pathfile(file_path):
    try:
        os.remove(file_path)
        sprint(self.script_name,"green", "Fichier Suprimé : " +file_path)
    except Exception as e:
            sprint(self.script_name,"red", "del_file Error : "+ str(e))
    # Supprimer le fichier après le traitement

def get_value_json(var_name, config):
    return config.get(var_name)



def send_message(tw_acc_pseudo, tw_acc_token, channel_name, Message_text):
    hprint("green","start send_message")
    
    command = '-pseudo "'+tw_acc_pseudo+'" -token "'+tw_acc_token+'" -twitchname "'+channel_name+'" -message " Kappa '+Message_text+'"'
    message_tosend = 'python send_message.py '+command
    hprint("yellow",f"send message = "+str(message_tosend))
    subprocess.run(message_tosend, shell=True)
    hprint("yellow",f"Finnish send message")



def clear_screen():
    os.system('clear')

def afficher_type(variable):
    """Affiche le type d'une variable."""
    print(f"Le type de la variable est : {type(variable).__name__}")

def stop_all():
    hprint("blue", "Arrêt d'enregistrement twitch.")
    recordTw.stop()
    sb_translation.stop()


def generation_responce():
    text_streamer = sb_translation.get_lasttext()
    hprint("blue", "start IA_generator")
    ask_text.main_ask(text_streamer)



















