So here I am porting my ancient newspipe front-end to Snakelets and Python, and I’ve just trimmed down over 20 lines of PHP down to essentially one line of BeautifulSoup retrieval:
def parseWapProfile(self, url): """ Invoked for unknown (uncached) UAs """ result = fetch.fetchURL(url) soup = BeautifulStoneSoup(result['data'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES) try: width, height = soup('prf:screensize')[0].contents[0].split('x') except: width = height = None return {"width": width, "height": height}
Of course there’s a lot more error handling to do (and useful data to glean off the XML), but being able to cut through all the usual parsing crap is immensely gratifying.
Comments have been automatically closed.
