Version 6 (modified by xrambous, 2 years ago) (diff)


PV277 Programming Applications for Social Robots (autumn 2019)

How to get info from web?


If API exists, you can usually use JSON data after send the right parameters. Example to get weather data.

import requests
url = ""

params = {'q': 'Brno',
          'units': 'metric',
          'lang': 'cz'}

r = requests.get(url=url, params=params)
data = r.json()


(Full example

Parse webpage data

If no API is provided, you can download and parse the webpage.

from bs4 import BeautifulSoup
import requests
page = requests.get(url).text
soup = BeautifulSoup(page, features="lxml")
results = soup.findAll('h2', attrs={'class':'article-title'})

(Full example

How to integrate info with robot?

Dialog variables

In dialog file, set value of variable, use it in Python script in behavior.

u:(["Můj [oblíbený nejoblíbenější] tým je" "Fandím {týmu}"] _*) $team=$1

First word after sentence is available in $1 and passed to the script as team variable.

def onInput_onStart(self, team):
    self.team_usr = team

Use TTS in script

veta = self.team_name + " má " + str(act_team.points) + " bodů"

Run script as service and parse service output

Attachments (7)

Download all attachments as: .zip