| 1 |
#!/usr/bin/env python |
| 2 |
__license__ = 'GPL v3' |
| 3 |
__copyright__ = '2011, Adrian Gunawan <agunawan at adrnalin.com>' |
| 4 |
__author__ = 'Adrian Gunawan' |
| 5 |
__version__ = 'v1.0' |
| 6 |
__date__ = '02 February 2011' |
| 7 |
|
| 8 |
''' |
| 9 |
http://www.thejakartapost.com/ |
| 10 |
''' |
| 11 |
|
| 12 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 13 |
|
| 14 |
|
| 15 |
class JakartaPost(BasicNewsRecipe): |
| 16 |
title = 'Jakarta Post' |
| 17 |
|
| 18 |
__author__ = 'Kovid Goyal' |
| 19 |
description = 'Indonesian Newspaper in English from Jakarta Post Online Edition' |
| 20 |
category = 'breaking news, national, business, international, Indonesia' |
| 21 |
language = 'en_ID' |
| 22 |
oldest_article = 2 |
| 23 |
max_articles_per_feed = 100 |
| 24 |
|
| 25 |
no_stylesheets = True |
| 26 |
no_javascript = True |
| 27 |
remove_empty_feeds = True |
| 28 |
|
| 29 |
timefmt = ' [%A, %d %B, %Y]' |
| 30 |
encoding = 'utf-8' |
| 31 |
ignore_duplicate_articles = {'title', 'url'} |
| 32 |
|
| 33 |
keep_only_tags = [ |
| 34 |
dict(name='h1'), |
| 35 |
dict(attrs={'class': lambda x: x and 'byline' in x.split()}), |
| 36 |
dict(attrs={'class': lambda x: x and 'span-13' in x.split()}), |
| 37 |
] |
| 38 |
remove_tags_after = dict(attrs={'class': lambda x: x and 'span-12' in x.split()}) |
| 39 |
|
| 40 |
def parse_jp_section(self, url): |
| 41 |
soup = self.index_to_soup(url) |
| 42 |
for div in soup.findAll('div', attrs={'class': 'story'}): |
| 43 |
a = div.find('a', href=True) |
| 44 |
url = a.get('href') |
| 45 |
title = self.tag_to_string(a) |
| 46 |
p = div.find('p') |
| 47 |
desc = self.tag_to_string(p) |
| 48 |
self.log('\t', title, ' at ', url) |
| 49 |
yield {'title': title, 'url': url, 'description': desc} |
| 50 |
|
| 51 |
def parse_index(self): |
| 52 |
ans = [] |
| 53 |
for sec in ( |
| 54 |
'editors_choice channel/headlines channel/business channel/national channel/archipelago channel/jakarta channel/world channel/sports' |
| 55 |
).split(): |
| 56 |
title = (sec.partition('/')[2] or sec).replace('_', ' ').capitalize() |
| 57 |
articles = list(self.parse_jp_section('http://www.thejakartapost.com/' + sec)) |
| 58 |
self.log('Found section:', title) |
| 59 |
if articles: |
| 60 |
ans.append((title, articles)) |
| 61 |
if self.test and len(ans) >= self.test[0]: |
| 62 |
break |
| 63 |
return ans |