Debian Codegraph @

recipes/toiprint.recipe

raw
1 from datetime import date
2
3 from calibre.web.feeds.news import BasicNewsRecipe, classes
4
5 # default edition is Delhi i.e., 'cap'
6 # Hyderabad - 'toih'; Delhi - 'cap'; Mumbai - 'toim'; Banglore - 'toibgc';
7 # Chennai - 'toich'; Chandigarh - 'toicgct'; Jaipur - 'toijc'; Kolkata - 'toikc';
8 # There are others too, try to figure it out, visit toi epaper link.
9
10 le = 'cap' # local edition;
11
12 date0 = date.today().strftime('%Y/%m/%d')
13
14 # for older edition change date0 below.
15 # date0 = '2023/09/15'
16
17 year, month, day = (int(x) for x in date0.split('/'))
18 dt = date(year, month, day)
19 date_ = dt.strftime('%d_%m_%Y')
20
21 img_index = 'https://cmsimages.timesgroup.com/image-resizer?epaper_s3_path=PublicationData/TOI/' + le + '/' + date0
22
23
24 class TOIPring(BasicNewsRecipe):
25 title = 'TOI Print Edition'
26 language = 'en_IN'
27 __author__ = 'Kovid Goyal'
28 masthead_url = 'https://static.toiimg.com/photo/98333929.cms'
29 timefmt = ' [' + dt.strftime('%b %d, %Y') + ']'
30 description = 'Articles from the Times of India epaper, digital edition'
31 encoding = 'utf-8'
32 remove_empty_feeds = True
33
34 keep_only_tags = [classes('printeditioncontentwrapper')]
35 remove_tags = [
36 classes('header-container popupWrapper footer_wrapper icon_share_wrap'),
37 {'id': 'blocker'},
38 {'name': 'style'},
39 ]
40
41 extra_css = '''
42 .sub { color:#202020; }
43 .auth { font-size:small; font-weight:bold; color:#202020; }
44 .cap { text-align:center; font-size:small; }
45 img { display:block; margin:0 auto; }
46 .info { font-size:small; color:#404040; }
47 .lead { color:#404040; }
48 '''
49
50 def parse_index(self):
51 url = 'https://epaper.indiatimes.com/english-news-paper-today-toi-print-edition/'
52 # url = 'file:///t/raw.html'
53 soup = self.index_to_soup(url)
54 ans = []
55 for sec in soup.find_all('section', attrs={'data-content': True}):
56 h1 = sec.find('h1')
57 section = self.tag_to_string(h1)
58 self.log(section)
59 articles = []
60 listing = sec.find_next_sibling(type='listing')
61 for a in listing.find_all('a', href=True):
62 url = a['href']
63 title = self.tag_to_string(a.find('h2'))
64 self.log(' ', title)
65 articles.append({'title': title, 'url': url})
66 if articles:
67 ans.append((section, articles))
68 return ans