def getTopStories(maxResults=None):
 hdr = {'User-Agent': 'Mozilla/5.0'}
 req = urllib2.Request(URL, headers=hdr)
 page = urllib2.urlopen(req).read()
 soup = BeautifulSoup(page)
 matches = soup.findAll('td', class_='title')
 matches = [m.a for m in matches if (m.a and (m.text != u'More'))]
 matches = [HNStory(m.text, m['href']) for m in matches]
 if maxResults:
  num_stories = min(maxResults, len(matches))
  return random.sample(matches, num_stories)
 return matches

def getTopStories ( maxResults = None ) : hdr = { 'User-Agent' : 'Mozilla/5.0' } req = urllib2 . Request ( URL , headers = hdr ) page = urllib2 . urlopen ( req ) . read ( ) soup = BeautifulSoup ( page ) matches = soup . findAll ( 'td' , class_ = 'title' ) matches = [ m . a for m in matches if ( m . a and ( m . text != u'More' ) ) ] matches = [ HNStory ( m . text , m [ 'href' ] ) for m in matches ] if maxResults : num_stories = min ( maxResults , len ( matches ) ) return random . sample ( matches , num_stories ) return matches
returns the top headlines from hacker news .