| 1 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 2 |
|
| 3 |
|
| 4 |
class GKT(BasicNewsRecipe): |
| 5 |
title = 'General Knowledge Today' |
| 6 |
language = 'en_IN' |
| 7 |
__author__ = 'Kovid Goyal' |
| 8 |
oldest_article = 7 # days |
| 9 |
max_articles_per_feed = 20 |
| 10 |
|
| 11 |
no_stylesheets = True |
| 12 |
no_javascript = True |
| 13 |
auto_cleanup = True |
| 14 |
|
| 15 |
def parse_index(self): |
| 16 |
securl = 'https://www.gktoday.in/current-affairs/' |
| 17 |
ans = {} |
| 18 |
|
| 19 |
def p_tags(h1): |
| 20 |
for sib in h1.next_siblings: |
| 21 |
if sib.name == 'h1': |
| 22 |
break |
| 23 |
if sib.name == 'p': |
| 24 |
yield sib |
| 25 |
|
| 26 |
def find_cat(ps): |
| 27 |
for p in ps: |
| 28 |
for a in p.findAll('a', rel='tag'): |
| 29 |
return self.tag_to_string(a) |
| 30 |
|
| 31 |
for i in range(1, 6): |
| 32 |
page = '' if i == 1 else 'page/' + str(i) |
| 33 |
self.log('Trying:', securl + page) |
| 34 |
soup = self.index_to_soup(securl + page) |
| 35 |
container = soup.find(**classes('left_middle_content')) |
| 36 |
for h1 in container.findAll('h1'): |
| 37 |
title = self.tag_to_string(h1) |
| 38 |
a = h1.find('a') |
| 39 |
if a is None: |
| 40 |
continue |
| 41 |
url = a['href'] |
| 42 |
ps = tuple(p_tags(h1)) |
| 43 |
category = find_cat(ps) or 'Unknown' |
| 44 |
ans.setdefault(category, []).append({'title': title, 'url': url, 'description': self.tag_to_string(ps[0])}) |
| 45 |
self.log('\t' + title + ' ' + url) |
| 46 |
return list(ans.items()) |