| 63 | Specify service script in manifest.xml: |
| 64 | {{{#!xml |
| 65 | <services> |
| 66 | <service autorun="true" execStart="/usr/bin/python2 scripts/rozvrh.py" name="rozvrh" /> |
| 67 | </services> |
| 68 | }}} |
| 69 | |
| 70 | In dialog, detect variables, pass them to service, and parse call result to say answer: |
| 71 | |
| 72 | {{{ |
| 73 | u:(rozvrh) Pro jakou místnost bys chtěl znát rozvrh? |
| 74 | u1:({pro} {místnost učebnu} _~letter _~number) Podívám se na rozvrh pro $1 $2 ^call(Rozvrh.get_current_lesson($1, $2)) \pau=500\ |
| 75 | c1:(In _* teaches _* course _*) V místnosti $1 je právě $3 s vyučujícím, který se jmenuje $2. |
| 76 | c1:(In _* currently _*) V místnosti $1 je právě $2 |
| 77 | }}} |
| 78 | |
| 79 | {{{u1}}} detects letter and number (concepts defined earlier in dialog) and calls get_current_lesson(). This function return strings, that are parsed in dialog and answer is translated to each locale. |
| 80 | |
| 81 | {{{#!python |
| 82 | def get_current_lesson(self, letter, number): |
| 83 | room = letter+str(number) |
| 84 | lesson = self.rozvrh.find_current_lesson(room) |
| 85 | if lesson: |
| 86 | if lesson.teacher: |
| 87 | teacher = lesson.teacher.split(' ')[-1] |
| 88 | return "In %s teaches %s course %s" % (lesson.room, teacher, lesson.name) |
| 89 | else: |
| 90 | return "In %s currently %s" % (lesson.room, lesson.name) |
| 91 | }}} |