From 85c1c53a534137a07a124cd0df396b656a735f71 Mon Sep 17 00:00:00 2001 From: yodha8 <104330897+yodha8@users.noreply.github.com> Date: Sun, 1 May 2022 06:40:34 -0700 Subject: [PATCH] Update cacm.recipe No need for username-password. Articles are free to read and can be retrieved from the RSS feed. --- recipes/cacm.recipe | 57 +++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/recipes/cacm.recipe b/recipes/cacm.recipe index 995dac0d15..4183458af7 100644 --- a/recipes/cacm.recipe +++ b/recipes/cacm.recipe @@ -1,39 +1,30 @@ -import datetime +#!/usr/bin/env python +# vim:fileencoding=utf-8 + from calibre.web.feeds.news import BasicNewsRecipe - -class AdvancedUserRecipe1286242553(BasicNewsRecipe): - title = u'CACM' - oldest_article = 7 +class CACM(BasicNewsRecipe): + title = "ACM CACM Magazine" + description = "Published on day 1 of every month." + oldest_article = 30 max_articles_per_feed = 100 - needs_subscription = True - feeds = [(u'CACM', u'http://cacm.acm.org/magazine.rss')] - language = 'en' - __author__ = 'jonmisurda' - no_stylesheets = True - remove_tags = [ - dict(name='div', attrs={'class': ['FeatureBox', 'ArticleComments', 'SideColumn', - 'LeftColumn', 'RightColumn', 'SiteSearch', 'MainNavBar', 'more', 'SubMenu', 'inner']}) + auto_cleanup = True + + feeds = [ + ('ACM CACM', 'https://cacm.acm.org/magazine.rss'), ] - cover_url_pattern = 'http://cacm.acm.org/magazines/%d/%d' - - def get_browser(self): - br = BasicNewsRecipe.get_browser(self) - if self.username is not None and self.password is not None: - br.open('https://cacm.acm.org/login') - br.select_form(nr=1) - br['current_member[user]'] = self.username - br['current_member[passwd]'] = self.password - br.submit() - return br - + def get_cover_url(self): - now = datetime.datetime.now() + """ + Parse out cover URL from cover page. + Example: + From: https://cacm.acm.org/system/assets/0004/2570/April2022.Cover.1000x1338.large.jpg?1647524668&1647524668 + Get: https://cacm.acm.org/system/assets/0004/2570/April2022.Cover.1000x1338.jpg + """ - cover_url = None - soup = self.index_to_soup(self.cover_url_pattern % - (now.year, now.month)) - cover_item = soup.find('img', attrs={'alt': 'magazine cover image'}) - if cover_item: - cover_url = cover_item['src'] - return cover_url + soup = self.index_to_soup("https://cacm.acm.org/") + a_img = soup.find("a", class_="menuCover") + img_url = a_img.img["src"] + img_url = img_url.split("?")[0] + img_url = img_url.replace(".large", "") + return img_url