From 1c645ec92a3abbfc5f1f41b48db21f9abd012b26 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 13 Oct 2020 23:43:59 +0200 Subject: [PATCH] Updated Procedures, event hooks and cronjobs as Python scripts (markdown) --- ...vent-hooks-and-cronjobs-as-Python-scripts.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Procedures,-event-hooks-and-cronjobs-as-Python-scripts.md b/Procedures,-event-hooks-and-cronjobs-as-Python-scripts.md index ef3a750..9cc2e99 100644 --- a/Procedures,-event-hooks-and-cronjobs-as-Python-scripts.md +++ b/Procedures,-event-hooks-and-cronjobs-as-Python-scripts.md @@ -51,4 +51,21 @@ from platypush.message.event.assistant import SpeechRecognizedEvent @hook(SpeechRecognizedEvent) def test_procedure(event, **content): print('Recognized speech: {}'.format(event.args['phrase'])) +``` +As well as cronjobs: + +```python +# ~/.config/platypush/scripts/test.py + +from platypush.cron import cron +from platypush.utils import run + +# Run it every minute +@cron('* * * * *') +def test_cron(event, **content): + import os + import datetime + + with open(os.path.expanduser('~/test.txt'), 'a') as f: + f.write('The time is: {}\n'.format(datetime.datetime.now().isoformat())) ``` \ No newline at end of file