File size: 4,064 Bytes
8287ef8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import gradio as gr
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time

# 🔧 Driver global
driver = None

# ✅ Connexion
def connexion(login, password):
    global driver

    options = Options()
    driver = webdriver.Chrome(options=options)

    try:
        driver.get("https://educonnect.education.gouv.fr/idp/profile/SAML2/Redirect/SSO?execution=e3s1")
        time.sleep(3)

        driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[1]/div/div[2]/button").click()
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[2]/div[3]/div/form/div[1]/input").send_keys(login)
        driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[2]/div[3]/div/form/div[2]/div[2]/input").send_keys(password)

        driver.find_element(By.XPATH, "/html/body/div[3]/div/div[2]/div[2]/div[3]/div/form/div[3]/button").click()

        time.sleep(5)

        driver.get("https://wilapa-guyane.com/auth/saml/wayf?callback=https%3A%2F%2Fwilapa-guyane.com%2F#/")
        time.sleep(5)

        driver.find_element(By.XPATH, "/html/body/default-styles/div/section/section/div[2]/a/div/i18n/span").click()

        return "✅ Connecté"

    except Exception as e:
        return f"❌ Erreur connexion : {e}"


# ✅ Envoyer message
def envoyer_message(message, destinataire):
    global driver

    try:
        driver.find_element(By.XPATH, "/html/body/ode-portal/ode-navbar/header/nav/div/ul/li[3]/a").click()
        time.sleep(3)

        driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[1]/div/div/div/button").click()
        time.sleep(2)

        champ = driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[2]/div[2]/div/div[1]/div/div[1]/div/div[1]/div/input")
        champ.send_keys(destinataire)
        time.sleep(2)

        driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[2]/div[2]/div/div[1]/div/div[1]/div/div[2]").click()

        champ_msg = driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[2]/div[2]/div/section/div[1]/div[2]/div/div/p[1]")
        champ_msg.send_keys(message)

        driver.find_element(By.XPATH, "/html/body/div[1]/div/main/div[2]/div[2]/div/div[3]/div/div/div/div[1]/button").click()

        return f"✅ Message envoyé à {destinataire}"

    except Exception as e:
        return f"❌ Erreur : {e}"


# ✅ Changer devise
def changer_devise(valeur):
    global driver

    try:
        champ = driver.find_element(By.XPATH, "/html/body/portal/div[2]/section/div[2]/container/div/div[2]/container/div/div[1]/div[2]/article/div/div/div/input")
        champ.clear()
        champ.send_keys(valeur)

        driver.find_element(By.XPATH, "/html/body/portal/div[2]/section/div[2]/container/div/div[2]/container/div/div[1]/div[2]/article/div/div/button/i18n/span").click()

        return f"✅ Devise changée : {valeur}"

    except Exception as e:
        return f"❌ Erreur : {e}"


# 🎨 Interface Gradio
with gr.Blocks() as app:
    gr.HTML("<h1>🤖 Bot Wilapa</h1>")

    with gr.Tab("Connexion"):
        login = gr.Textbox(label="Identifiant")
        password = gr.Textbox(label="Mot de passe", type="password")
        btn_login = gr.Button("Se connecter")
        out_login = gr.Textbox()

        btn_login.click(connexion, inputs=[login, password], outputs=out_login)

    with gr.Tab("Envoyer message"):
        message = gr.Textbox(label="Message")
        dest = gr.Textbox(label="Destinataire")
        btn_send = gr.Button("Envoyer")
        out_send = gr.Textbox()

        btn_send.click(envoyer_message, inputs=[message, dest], outputs=out_send)

    with gr.Tab("Changer devise"):
        devise = gr.Textbox(label="Nouvelle valeur")
        btn_dev = gr.Button("Changer")
        out_dev = gr.Textbox()

        btn_dev.click(changer_devise, inputs=devise, outputs=out_dev)

app.launch()