''' Purpose: introducing the acquisition of web data -- determine the hidden super power of a CS 1112 person ''' # need help to get web data - so import some capabilities import urllib.request # define the base folder for course participants BASE_PEOPLE_URL = 'http://www.cs.virginia.edu/~cs1112/people/' # get computing id of interest and clean it up into canonical form; # i.e., in lowercase and without surrounding whitespace reply = input( 'Enter computing id: ' ) id = reply.strip() id = id.lower() # specify web folder of indicated person folder = BASE_PEOPLE_URL + id + '/' # specify link for super power web file of indicated person web_file = folder + 'power.txt' # get a connection to the web resource of interest stream = urllib.request.urlopen( web_file ) # read stream to get its contents (the returned contents are not # normal text) bytes = stream.read() # decode contents into plain text form contents = bytes.decode( 'UTF-8' ) # text is the superpower of interest print( contents )