Changes between Version 25 and Version 26 of en/ProgrammingRobotsCourse/GettingWwwInfo


Ignore:
Timestamp:
Mar 16, 2020, 6:33:30 PM (4 years ago)
Author:
xrambous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • en/ProgrammingRobotsCourse/GettingWwwInfo

    v25 v26  
    226226 * Connect `onStopped` output of `Say Text` box with `onStopped`.
    227227        [[Image(statapp.png)]]
     228 * Double-click the Python script to edit the script, and exchange autogenerated script with the following:
     229   {{{
     230class MyClass(GeneratedClass):
     231    def __init__(self):
     232        GeneratedClass.__init__(self)
     233
     234    def onLoad(self):
     235        #put initialization code here
     236        pass
     237
     238    def onUnload(self):
     239        #put clean-up code here
     240        pass
     241
     242    def onInput_onStart(self, country):
     243        #self.onStopped() #activate the output of the box
     244        self.logger.info("start")
     245        self.logger.info(self.getStat(country))
     246        self.returnStat(self.getStat(country))
     247
     248    def onInput_onStop(self):
     249        self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
     250        self.onStopped() #activate the output of the box
     251
     252    def getStat(self, country):
     253        import urllib2
     254        url = 'https://opendata.arcgis.com/datasets/bbb2e4f589ba40d692fab712ae37b9ac_2.csv'
     255        response = urllib2.urlopen(url)
     256        csv = response.read()
     257        for line in csv.splitlines():
     258            data = line.split(',')
     259            if data[3] == country:
     260                return 'Počet nakažených je '+data[7]
     261}}}