''' Purpose: determine the hidden super power of a CS 1112 person ''' # need help to get web data - so import the capability from urllib.request import urlopen # define the base folder for course participants BASE_CS1112_PEOPLE_URL = 'http://www.cs.virginia.edu/~cs1112/people/' # So the people folder is the base folder! The people # folder contains all of your submissions! :) FILE_NAME = 'my-power.txt' # get computing id of interest reply = input( 'Enter computing id: ' ) # If I write " nAh3zb" # clean up the reply to get the user id user_id = reply.strip() # Remove leading and trailing whitespace ("nAh3zb") user_id = user_id.lower() # Make the user_id lowercase now ("nah3zb") # specify web folder of indicated person web_folder = BASE_CS1112_PEOPLE_URL + user_id + '/' # people/compid/ <- this is the last slash! print( "Web folder = ", web_folder ) # specify link for super power web file of indicated person link = web_folder + FILE_NAME print( "Link=", link ) # get a connection to stream the web resource of interest stream = urlopen( link ) # It's just a connection to the web where it goes into that link and # establishes a connection with that link. # read stream to gets its encoded contents encoding = stream.read() # Now take that connection and read what's in the stream (that connection) # decode contents into plain text form text = encoding.decode( 'UTF-8' ) # Take the encoded version and decode it using plain old text. print( text ) # cleaned-up text is the superpower of interest power = text.strip() # print power print( power ) # So we see how we went to the folder people and then took a computing # id, went into that person's directory, and then got their my-power.txt # and then got the contents of that webpage, decoded it, and then # printed out their power!