mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
45 lines
1.5 KiB
Plaintext
45 lines
1.5 KiB
Plaintext
from calibre.web.feeds.news import BasicNewsRecipe
|
|
|
|
|
|
class GKT(BasicNewsRecipe):
|
|
title = u'General Knowledge Today'
|
|
language = 'en_IN'
|
|
__author__ = 'Kovid Goyal'
|
|
oldest_article = 7 # days
|
|
max_articles_per_feed = 20
|
|
|
|
no_stylesheets = True
|
|
no_javascript = True
|
|
auto_cleanup = True
|
|
|
|
def parse_gkt_section(self, url, ignore_error=False):
|
|
try:
|
|
root = self.index_to_soup(url, as_tree=True)
|
|
except Exception:
|
|
if ignore_error:
|
|
return
|
|
raise
|
|
for a in root.xpath('//div[@class="posts-listing"]/h1/a[@href]'):
|
|
title = self.tag_to_string(a).strip()
|
|
url = a.get('href')
|
|
if title and url:
|
|
self.log('\tFound article:', title, 'at', url)
|
|
yield {'title': title, 'url': url}
|
|
|
|
def parse_index(self):
|
|
url = 'http://www.gktoday.in/'
|
|
root = self.index_to_soup(url, as_tree=True)
|
|
ans = []
|
|
h3 = root.xpath('//h3[@class="widget-title"]')[1]
|
|
for a in h3.getparent().xpath('descendant::li/a[@href]'):
|
|
category = self.tag_to_string(a).strip()
|
|
if 'PDF' in category or not category:
|
|
continue
|
|
url = a.get('href')
|
|
self.log('Found section:', category, 'at', url)
|
|
articles = list(self.parse_gkt_section(url)) + \
|
|
list(self.parse_gkt_section(url + '/page/2', ignore_error=True))
|
|
if articles:
|
|
ans.append((category, articles))
|
|
return ans
|