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
This commit is contained in:
22
actions/http_example.py
Normal file
22
actions/http_example.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/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,
|
||||
}
|
||||
Reference in New Issue
Block a user