From 4346f55b29f980d640f8ee56180c43e03f84e271 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Wed, 15 Dec 2021 20:37:21 -0500 Subject: [PATCH] Python examples; that's all; closes #50 --- docs/index.md | 6 ++++++ docs/subscribe/api.md | 16 ++++++++++++++++ examples/subscribe-python/subscribe.py | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100755 examples/subscribe-python/subscribe.py diff --git a/docs/index.md b/docs/index.md index e0635d7a..c8c85501 100644 --- a/docs/index.md +++ b/docs/index.md @@ -52,6 +52,12 @@ is in the request body. Here's an example showing how to publish a simple messag strings.NewReader("Backup successful 😀")) ``` +=== "Python" + ``` python + requests.post("https://ntfy.sh/mytopic", + data="Backup successful 😀".encode(encoding='utf-8')) + ``` + === "PHP" ``` php-inline file_get_contents('https://ntfy.sh/mytopic', false, stream_context_create([ diff --git a/docs/subscribe/api.md b/docs/subscribe/api.md index 4a0bb858..8a57bd6b 100644 --- a/docs/subscribe/api.md +++ b/docs/subscribe/api.md @@ -54,6 +54,14 @@ recommended way to subscribe to a topic**. The notable exception is JavaScript, } ``` +=== "Python" + ``` python + resp = requests.get("https://ntfy.sh/disk-alerts/json", stream=True) + for line in resp.iter_lines(): + if line: + print(line) + ``` + === "PHP" ``` php-inline $fp = fopen('https://ntfy.sh/disk-alerts/json', 'r'); @@ -150,6 +158,14 @@ format. Keepalive messages are sent as empty lines. } ``` +=== "Python" + ``` python + resp = requests.get("https://ntfy.sh/disk-alerts/raw", stream=True) + for line in resp.iter_lines(): + if line: + print(line) + ``` + === "PHP" ``` php-inline $fp = fopen('https://ntfy.sh/disk-alerts/raw', 'r'); diff --git a/examples/subscribe-python/subscribe.py b/examples/subscribe-python/subscribe.py new file mode 100755 index 00000000..892392eb --- /dev/null +++ b/examples/subscribe-python/subscribe.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import requests + +resp = requests.get("https://ntfy.sh/mytopic/json", stream=True) +for line in resp.iter_lines(): + if line: + print(line)