Square Peg, Round Hole

Sitting in the wine aisle at the grocery store… wondering which brand to buy. Have we had that before? If so, was it good or did it suck?

I know: I’ll hit our cork’d page to see what we’ve reviewed! On my new cell phone! Shit, that site loads slowly. They only show 15 wines at a time. And, they show the average score for the wine. I don’t care about that shit; I need to know how we ranked it.

Oh, look! They have an RSS feed for us. Uh oh, no RSS reader app on the cell phone. Even then, the feed only supplies the name of the wine, and provides a link to its collective cork’d review.

Gah! This blows.

If you want something done right, do it yourself:

import urllib2
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup

RSS_FEED = 'http://www.corkd.com/feed/journal/xiix'
USERID = u'xiix' # unicode nec.

def getPage(URL):
    page = urllib2.urlopen(URL)
    txt = page.read()
    page.close()
    return txt

def getScore(URL):
    soup = BeautifulSoup(getPage(URL))
    for a in soup('a'):
        al = a.contents
        if USERID in al:
            for abbr in a.findAllNext('abbr'):
                if (u'class', u'rating') in abbr.attrs:
                    return abbr.contents[0]

def fetchScores():
    FINAL = {}
    txt = getPage(RSS_FEED)
    soup = BeautifulStoneSoup(txt)
    for x in soup('item'):
        winename = x.title.string
        revlink = x.link.string
        FINAL[winename] = getScore(revlink)
    return FINAL

Stick that shit in a weekly cronjob. Sort and format the output for victory.

WIN: The Low-Overhead, Fast-Loading, Cell-Phone-Compatible List of Wines and Scores

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s