File size: 1,853 Bytes
2141129 1618dd5 b2ea75f 076de42 2141129 93c0f73 2141129 93c0f73 2141129 b2ea75f 1618dd5 b2ea75f 93c0f73 b2ea75f 74a5aa4 93c0f73 b2ea75f 93c0f73 b2ea75f 1618dd5 076de42 1618dd5 93c0f73 1618dd5 93c0f73 5589c67 1618dd5 2141129 b2ea75f 2141129 93c0f73 ad81629 2141129 93c0f73 ad81629 93c0f73 ad81629 2141129 93c0f73 2141129 1618dd5 |
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 |
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:
# Recupera as variáveis de ambiente seguras
wp_app_password = os.getenv("WP_APP_PASSWORD")
wp_user = os.getenv("WP_USER")
wp_url = os.getenv("WP_URL")
# Verifica se as variáveis estão definidas
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."
# URL do endpoint da API REST
api_url = f"{wp_url}/wp-json/wp/v2/{endpoint}"
# Configura a autenticação
auth = HTTPBasicAuth(wp_user, wp_app_password)
# Executa a requisição GET no endpoint da API REST
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)}"
# Lista de endpoints básicos da API REST
endpoints = [
"posts",
"users",
"categories"
]
# Cria a interface Gradio
iface = gr.Interface(
fn=test_wp_rest_api, # Função que será chamada
inputs=[
gr.Dropdown(choices=endpoints, label="Endpoint da API REST") # Menu suspenso para selecionar o endpoint
],
outputs="text", # Saída de texto com o resultado
title="Testador de API REST do WordPress", # Título do painel
description="Selecione um endpoint da API REST para testar." # Descrição do painel
)
# Inicia a interface
iface.launch()
|