Debian Codegraph @

recipes/pc_world.recipe

raw
1 #!/usr/bin/env python
2
3 """
4 http://www.pcworld.com/
5 """
6
7 from calibre.web.feeds.news import BasicNewsRecipe, classes
8
9
10 class pcWorld(BasicNewsRecipe):
11 __author__ = 'unkn0wn'
12 description = 'PCWorld helps you navigate the PC ecosystem to find the products you want and the advice you need to get the job done.'
13 title = 'PCWorld'
14 publisher = 'IDG Communication'
15 language = 'en'
16 encoding = 'utf-8'
17 ignore_duplicate_articles = {'url'}
18 remove_javascript = True
19 resolve_internal_links = True
20 remove_empty_feeds = True
21 remove_attributes = ['height', 'width']
22
23 extra_css = '''
24 .entry-meta, .imageCredit {font-size:small;}
25 .entry-eyebrow, .article_author_box_bio {font-size:small; color:#404040;}
26 .subheadline {font-style:italic; color:#202020;}
27 '''
28
29 keep_only_tags = [classes('entry-header post-thumbnail'), dict(name='div', attrs={'id': 'link_wrapped_content'}), classes('article_author_box_bio')]
30
31 def parse_index(self):
32
33 section_list = [
34 ('PC & Components', 'pc-components'),
35 ('Laptops', 'laptops'),
36 ('Mobile', 'mobile'),
37 ('How-To', 'howto'),
38 ('Gaming', 'gaming'),
39 ('Windows', 'windows'),
40 ('Best-Picks', 'best-picks'),
41 ('Reviews', 'reviews'),
42 ('Security', 'security'),
43 ('Smart Tech', 'smart-tech'),
44 ('Software', 'software'),
45 ('WiFi & Networks', 'wifi-networks'),
46 ('Deals', 'deals'),
47 ('Business', 'business'),
48 ('Entertainment', 'entertainment'),
49 ]
50
51 feeds = []
52
53 # For each section title, fetch the article urls
54 for section in section_list:
55 section_title = section[0]
56 section_url = 'https://www.pcworld.com/' + section[1]
57 self.log(section_title, section_url)
58 soup = self.index_to_soup(section_url)
59 articles = self.articles_from_soup(soup)
60 if articles:
61 feeds.append((section_title, articles))
62 return feeds
63
64 def articles_from_soup(self, soup):
65 ans = []
66 feed = soup.find('div', attrs={'class': lambda x: x and 'articleFeed-inner' in x.split()})
67 for item in feed.findAll('div', attrs={'class': 'item-text-inner'}):
68 a = item.find('h3').find('a', href=True)
69 title = self.tag_to_string(a)
70 url = a['href']
71 desc = ''
72 if span := item.find(attrs={'class': 'item-excerpt'}):
73 desc = self.tag_to_string(span)
74 if byline := item.find(attrs={'class': 'item-byline'}):
75 desc = self.tag_to_string(byline) + ' | ' + desc
76 if eye := item.find(attrs={'class': lambda x: x and 'item-eyebrow' in x.split()}):
77 desc = self.tag_to_string(eye) + ' | ' + desc
78 if itdate := item.find(attrs={'class': 'item-date'}):
79 date = self.tag_to_string(itdate)
80 check = 'hours', 'day', 'days' # skipping articles older than a week
81 if not any(x in date for x in check):
82 continue
83 if not url or not title:
84 continue
85 self.log('\t', title, '\n\t', desc, '\n\t\t', url)
86 ans.append({'title': title, 'url': url, 'description': desc})
87 return ans
88
89 def get_cover_url(self):
90 soup = self.index_to_soup('https://www.magzter.com/US/IDG-Consumer-and-SMB,-Inc./PCWorld/Computer-&-Mobile/')
91 return soup.find('img', id=lambda s: s and 'mgd__lhd__cover' in s.split())['src']