Tuesday, March 9, 2010

March Madness Entry 9

With an ever shrinking budget of time, a slew of stomach cramps, several sub 5 hour slumber nights, a new project at work, and the ever present long meeting for FUBAR's future tonight, I knew I had to make it short. At least I kept it useful.

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