|
|
import gradio as gr |
|
|
import requests |
|
|
import os |
|
|
from requests.auth import HTTPBasicAuth |
|
|
|
|
|
def test_wp_rest_api(endpoint): |
|
|
""" |
|
|
Função para testar endpoints básicos da API REST do WordPress. |
|
|
""" |
|
|
try: |
|
|
|
|
|
wp_app_password = os.getenv("WP_APP_PASSWORD") |
|
|
wp_user = os.getenv("WP_USER") |
|
|
wp_url = os.getenv("WP_URL") |
|
|
|
|
|
|
|
|
if not wp_app_password: |
|
|
return "Erro: Variável de ambiente WP_APP_PASSWORD não definida." |
|
|
if not wp_user: |
|
|
return "Erro: Variável de ambiente WP_USER não definida." |
|
|
if not wp_url: |
|
|
return "Erro: Variável de ambiente WP_URL não definida." |
|
|
|
|
|
|
|
|
api_url = f"{wp_url}/wp-json/wp/v2/{endpoint}" |
|
|
|
|
|
|
|
|
auth = HTTPBasicAuth(wp_user, wp_app_password) |
|
|
|
|
|
|
|
|
response = requests.get(api_url, auth=auth) |
|
|
|
|
|
if response.status_code != 200: |
|
|
return f"Erro ao acessar o endpoint: {response.text}" |
|
|
|
|
|
return response.json() |
|
|
except Exception as e: |
|
|
return f"Erro: {str(e)}" |
|
|
|
|
|
|
|
|
endpoints = [ |
|
|
"posts", |
|
|
"users", |
|
|
"categories" |
|
|
] |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=test_wp_rest_api, |
|
|
inputs=[ |
|
|
gr.Dropdown(choices=endpoints, label="Endpoint da API REST") |
|
|
], |
|
|
outputs="text", |
|
|
title="Testador de API REST do WordPress", |
|
|
description="Selecione um endpoint da API REST para testar." |
|
|
) |
|
|
|
|
|
|
|
|
iface.launch() |
|
|
|