Changes between Version 6 and Version 7 of en/ProgrammingRobotsCourse/GettingWwwInfo


Ignore:
Timestamp:
Oct 28, 2019 5:02:12 PM (3 months ago)
Author:
xrambous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • en/ProgrammingRobotsCourse/GettingWwwInfo

    v6 v7  
    6161=== Run script as service and parse service output
    6262
     63Specify 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
     70In dialog, detect variables, pass them to service, and parse call result to say answer:
     71
     72{{{
     73u:(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
     82def 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}}}