Debian Codegraph @

recipes/nytimes_cooking.recipe

raw
1 #!/usr/bin/env python
2 # vim:fileencoding=utf-8
3 from calibre.web.feeds.news import BasicNewsRecipe, prefixed_classes
4
5
6 class NYTCooking(BasicNewsRecipe):
7 title = 'NY Times Cooking'
8 description = 'NY Times Cooking Magazine'
9 __author__ = 'gourav'
10 language = 'en_US'
11 encoding = 'utf-8'
12 oldest_article = 2
13 max_articles_per_feed = 30
14 remove_attributes = ['style']
15 no_stylesheets = True
16 keep_only_tags = [
17 prefixed_classes('pagecontent_recipe-wrap__'),
18 ]
19 remove_tags = [
20 prefixed_classes(
21 'adunit_ad-unit__ recipeintro_tools-block__ notessection_notesPrintLayout__ notessection_notesSection__'
22 ' ratingssection_ratingsSection__ ingredients_buttons__'
23 ),
24 dict(name='source'),
25 ]
26
27 def parse_index(self):
28 url = 'https://cooking.nytimes.com/topics/what-to-cook-this-week'
29 soup = self.index_to_soup(url)
30
31 articles = soup.find_all('div', class_='card-info-wrapper')
32 feed = []
33
34 for i in articles:
35 article = {}
36 article['url'] = i.find('a')['href']
37 if article['url'].startswith('/'):
38 article['url'] = 'https://cooking.nytimes.com' + article['url']
39 article['title'] = i.find('h3').text.strip()
40 author = i.find('p', class_='card-byline')
41 article['author'] = author.text if author is not None else 'Unknown'
42 feed.append(article)
43
44 return [('Recipes', feed)]