Advertisement
Guest User

Calibre CACM Recipe

a guest
Oct 4th, 2010
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import datetime
  2. from calibre.ebooks.BeautifulSoup import Tag
  3.  
  4. class AdvancedUserRecipe1286242553(BasicNewsRecipe):
  5.     title          = u'CACM'
  6.     oldest_article = 7
  7.     max_articles_per_feed = 100
  8.     needs_subscription = True
  9.     feeds          = [(u'CACM', u'http://cacm.acm.org/magazine.rss')]
  10.     no_stylesheets        = True
  11.     remove_tags = [
  12.         dict(name='div', attrs={'class':['FeatureBox', 'ArticleComments', 'SideColumn', \
  13.               'LeftColumn', 'RightColumn', 'SiteSearch', 'MainNavBar','more', 'SubMenu', 'inner']})
  14.     ]
  15.     cover_url_pattern = 'http://cacm.acm.org/magazines/%d/%d'
  16.  
  17.     def get_browser(self):
  18.         br = BasicNewsRecipe.get_browser()
  19.         if self.username is not None and self.password is not None:
  20.             br.open('https://cacm.acm.org/login')
  21.             br.select_form(nr=1)
  22.             br['current_member[user]']   = self.username
  23.             br['current_member[passwd]'] = self.password
  24.             br.submit()
  25.         return br
  26.  
  27.     def get_cover_url(self):
  28.         now = datetime.datetime.now()
  29.  
  30.         cover_url = None
  31.         soup = self.index_to_soup(self.cover_url_pattern % (now.year, now.month))
  32.     print self.cover_url_pattern % (now.year, now.month)
  33.         cover_item = soup.find('img',attrs={'alt':'magazine cover image'})
  34.         if cover_item:
  35.            cover_url = cover_item['src']
  36.         return cover_url
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement