Ladies and gentlemen, the daily morning Python script (in function form for future porting to other applications) - Is it going to rain? Powered by Going To Rain?.
Very simple. Use urllib (1, not 2. Yes, there is a difference, it isn't just versioning differences...) to grab a url as a page we can step through, and look until we find a segment of HTML where I know the answer is stored. Once I find that marker, I know the answer is on the very next line, so just check to see if it says "yes".
def isitgoingtorain(): answerPage = urllib.urlopen("http://www.goingtorain.com") tmpLine = "" while answerPage.readline().find("<div id=\"answer\">") is -1: pass if answerPage.readline().find("yes") is not -1: return "yes." else: return "no."
No comments:
Post a Comment