 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
function that gets the current temperature
import urllib # We need to import the URL library
def findTemperatureREMOVEDve():
#Just like opening, reading and then closing a file
connection = urllib.urlopen("http://www.ajc.com/weather")
weather = connection.read()
connection.close()
# Now that the contents of the web page are in a string, finding
# the temperature is the same as it was for the version where the
# string was read from a local HTML file.
weather.find("Currently")
if currentlyIndex <> -1:
degreeIndex = weather.find("<b>°", currentlyIndex)
lessThanIndex = weather.rfind(">", 0, degreeIndex)
return weather[lessThanIndex + 1:degreeIndex]
if currentlyIndex == -1:
return “Can't find the temp"
Link to this Page