From d36d4fb5439b6b8abc18bc90080e53c1daf71bf5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C4=93teris=20Caune?=
Date: Thu, 29 Nov 2018 11:11:44 +0200
Subject: [PATCH] Additional python usage examples
---
CHANGELOG.md | 2 +-
hc/front/management/commands/pygmentize.py | 1 +
templates/front/docs.html | 8 ++++++++
templates/front/snippets/python_requests_payload.html | 8 ++++++++
templates/front/snippets/python_requests_payload.txt | 7 +++++++
5 files changed, 25 insertions(+), 1 deletion(-)
create mode 100644 templates/front/snippets/python_requests_payload.html
create mode 100644 templates/front/snippets/python_requests_payload.txt
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a1fddc0b..922c4d33 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
### Improvements
- Set Pushover alert priorities for "down" and "up" events separately
-
+- Additional python usage examples
### Bug Fixes
- Fix after-login redirects (the "?next=" query parameter)
diff --git a/hc/front/management/commands/pygmentize.py b/hc/front/management/commands/pygmentize.py
index b068fc24..5af2eb8e 100644
--- a/hc/front/management/commands/pygmentize.py
+++ b/hc/front/management/commands/pygmentize.py
@@ -36,6 +36,7 @@ class Command(BaseCommand):
_process("python_urllib2", lexers.PythonLexer())
_process("python_requests", lexers.PythonLexer())
_process("python_requests_fail", lexers.PythonLexer())
+ _process("python_requests_payload", lexers.PythonLexer())
_process("php", lexers.PhpLexer())
_process("powershell", lexers.shell.PowerShellLexer())
_process("powershell_inline", lexers.shell.BashLexer())
diff --git a/templates/front/docs.html b/templates/front/docs.html
index 3b5049d1..bf90b936 100644
--- a/templates/front/docs.html
+++ b/templates/front/docs.html
@@ -174,6 +174,14 @@ thing: they fire off a HTTP GET method.
{% include "front/snippets/python_urllib2.html" %}
+
+ You can include additional diagnostic information in the
+ in the request body (for POST requests), or in the "User-Agent"
+ request header:
+
+
+{% include "front/snippets/python_requests_payload.html" %}
+
Ruby
{% include "front/snippets/ruby.html" %}
diff --git a/templates/front/snippets/python_requests_payload.html b/templates/front/snippets/python_requests_payload.html
new file mode 100644
index 00000000..cc2c2cdf
--- /dev/null
+++ b/templates/front/snippets/python_requests_payload.html
@@ -0,0 +1,8 @@
+# Passing diagnostic information in the POST body:
+import requests
+requests.post("{{ ping_url }}", data="temperature=-7")
+
+# Passing diagnostic information in the User-Agent header:
+import requests
+requests.get("{{ ping_url }}", headers={"User-Agent": "temperature=-7"})
+
diff --git a/templates/front/snippets/python_requests_payload.txt b/templates/front/snippets/python_requests_payload.txt
new file mode 100644
index 00000000..a7a42bc8
--- /dev/null
+++ b/templates/front/snippets/python_requests_payload.txt
@@ -0,0 +1,7 @@
+# Passing diagnostic information in the POST body:
+import requests
+requests.post("PING_URL", data="temperature=-7")
+
+# Passing diagnostic information in the User-Agent header:
+import requests
+requests.get("PING_URL", headers={"User-Agent": "temperature=-7"})
\ No newline at end of file