Jupyter
Las funciones de la edinn API se pueden probar o usar utilizando Jupyter. En este documento veremos un ejemplo.
1º Instalar Python y Jupyter (si no está ya instalado):
- Verifica si Python está instalado abriendo una ventana de terminal y ejecutando el comando python --version
- Si Python no está instalado, descárgalo e instálalo desde https://www.python.org/downloads/.
- Verifica si Jupyter está instalado abriendo una ventana de terminal y ejecutando el comando jupyter --version
- Si Jupyter no está instalado ejecuta el comando pip install jupyter para instalarlo
2º Crear un archivo Jupyter:
- Abre o crea cualquir repositorio vacio.
- Abre esta carpeta desde terminal.
- Ejecuta el comando jupyter notebook
- Crea un nuevo archivo pulsando al botón New
3º Copiar y pegar el codigo siguente
Cell 1: Instala las librerias requeridos
# Install the requests library if not already installed
!pip install requests
Cell 2: Configuración
# --- Edinn API Configuration ---
EDINN_API_URL = "http://localhost:8080" # Replace with your edinn API URL
EDINN_COMPANY = "1231231234" # Replace with your company name
EDINN_USER = "user" # Replace with your username
EDINN_PASSWORD = "123asd" # Replace with your password
EDINN_PROCESS = "A0L1"
EDINN_DATEFROM = "202407180000000"
EDINN_DATETO = "202407190000000"
Cell 3: Funciones
import requests
import json
# --- Function to create an edinn session ---
def create_edinn_session():
url = f"{EDINN_API_URL}/sessions"
data = {
"company": EDINN_COMPANY,
"user": EDINN_USER,
"password": EDINN_PASSWORD
}
try:
response = requests.post(url, data=data)
response.raise_for_status()
session_id = response.json()["data"]
print(f"Created edinn session: {session_id}")
return session_id
except requests.exceptions.RequestException as e:
print(f"Error creating edinn session: {e}")
return None
# --- Function to delete an edinn session ---
def delete_edinn_session(session_id):
url = f"{EDINN_API_URL}/sessions/{session_id}?company={EDINN_COMPANY}"
try:
response = requests.delete(url)
response.raise_for_status()
print(f"Deleted edinn session: {session_id}")
except requests.exceptions.RequestException as e:
print(f"Error deleting edinn session: {e}")
def get_results():
url = f"{EDINN_API_URL}/results?company={EDINN_COMPANY}&session={session_id}&process={EDINN_PROCESS}&datefrom={EDINN_DATEFROM}&dateto={EDINN_DATETO}"
try:
response = requests.get(url)
response.raise_for_status() # Check for HTTP errors
data = response.json() # Parse the JSON response
print(f"Data from edinn:")
print(json.dumps(data, indent=4)) # Pretty-print the JSON data
except requests.exceptions.RequestException as e:
print(f"Error finding data: {e}")
Cell 5: Ejecuta la applicación
# --- Create edinn session ---
session_id = create_edinn_session()
get_results()
delete_edinn_session(session_id)
4º Configurar tus credenciales de la API de edinn:
- Reemplaza los valores de marcador de posición en la sección de Configuración de la API de edinn con tu URL real de la API de edinn, nombre de la empresa, nombre de usuario y contraseña.
5º Ejecutar el script:
Este script se conectará a la API de edinn, creará una sesión, recuperará datos y luego eliminará la sesión. Los datos recuperados se imprimirán en la consola en una estructura JSON formateada