Files
python_example/actions/http_example.py
David Culbreth f3c159913e Initial commit: Python Example Pack for Attune
Includes:
- 3 Python actions (hello, http_example, read_counter)
- 1 counter trigger type
- 1 counter sensor (Python, keystore-backed, per-rule state)
- 1 example rule (count_and_log)
- requirements.txt with requests and pika
- README with full usage documentation
2026-02-11 08:18:43 -06:00

23 lines
616 B
Python

#!/usr/bin/env python3
"""
HTTP Example Action - Python Example Pack
Demonstrates using the `requests` library to make an HTTP call to example.com.
Receives parameters via stdin JSON (through the Python wrapper).
"""
import requests
def run(url="https://example.com", **kwargs):
"""Fetch a URL and return status and a snippet of the response body."""
response = requests.get(url, timeout=10)
return {
"status_code": response.status_code,
"url": response.url,
"content_length": len(response.text),
"snippet": response.text[:500],
"success": response.ok,
}