mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-12-22 17:52:30 +01:00
Python examples; that's all; closes #50
This commit is contained in:
parent
92f48fbbea
commit
4346f55b29
3 changed files with 30 additions and 0 deletions
|
@ -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([
|
||||
|
|
|
@ -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');
|
||||
|
|
8
examples/subscribe-python/subscribe.py
Executable file
8
examples/subscribe-python/subscribe.py
Executable file
|
@ -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)
|
Loading…
Reference in a new issue