Page 316 -
P. 316

ask for an athlete



                                                 You were to assume that you have a CGI script called cgi-bin/
                                              1
                                                 generate_data.py, which, when called requests the data for
                                                 a named athlete from the server.
                                Provide the name of  You were to provide the code (which includes a call to
                                 the CGI to run.  the send_to_server() function) to implement this
                                                 functionality:

                           get_data_cgi  = '/cgi-bin/generate_data.py'
           Send the request
           to the web server,   send_to_server(web_server + get_data_cgi, {'which_athlete': which_athlete})
            together with the
            athlete name.                                                                Include the data.
                  Additionally, you were to write the code required to display the list of times returned from the server within
              2   an Android dialog:               Which button was pressed?



           When your user   if resp['which'] in ('positive'):                              The index value
           taps the “positive”                                                             is in the first
            button…work out       selected_athlete = app.dialogGetSelectedItems().result[0]  element of the
            the index value                                                                list of results
            chosen.                                                                         returned from the
                                which_athlete = athlete_names[selected_athlete]             dialog.
              Look up the
              athlete’s name using
             the index value.                                                                Send a new
                                athlete = json.loads(send_to_server(web_server + get_data_cgi,  web request
                                                                                             to the server
              Dynamically                                       {'which_athlete': which_athlete}))  to fetch the
              create the                                                                     athlete’s data.
              dialog’s title.
                                athlete_title = which_athlete + ' top 3 times:'

                                app.dialogCreateAlert(athlete_title)

           The user needs       app.dialogSetItems(athlete['Top3'])
            to see only the
            data this time, so       app.dialogSetPositiveButtonText('OK’)
            you need to use
            “dialogSetItems()”.      app.dialogShow()                  Set the single
                                                                       button’s text.


             Wait for a tap
             from the user.      resp = app.dialogGetResponse().result



           280    Chapter 8
   311   312   313   314   315   316   317   318   319   320   321