| 1 |
import random |
| 2 |
|
| 3 |
from calibre import browser |
| 4 |
from calibre.web.feeds.recipes import BasicNewsRecipe |
| 5 |
|
| 6 |
|
| 7 |
class AdvancedUserRecipe1325006965(BasicNewsRecipe): |
| 8 |
title = 'The Sun UK' |
| 9 |
description = 'Articles from The Sun tabloid UK' |
| 10 |
__author__ = 'Dave Asbury' |
| 11 |
# last updated 5/5/13 better cover fetch |
| 12 |
language = 'en_GB' |
| 13 |
oldest_article = 1 |
| 14 |
max_articles_per_feed = 15 |
| 15 |
remove_empty_feeds = True |
| 16 |
|
| 17 |
masthead_url = 'http://www.thesun.co.uk/sol/img/global/Sun-logo.gif' |
| 18 |
encoding = 'UTF-8' |
| 19 |
remove_javascript = True |
| 20 |
no_stylesheets = True |
| 21 |
|
| 22 |
ignore_duplicate_articles = {'title', 'url'} |
| 23 |
compress_news_images = True |
| 24 |
|
| 25 |
keep_only_tags = [ |
| 26 |
dict(name='div', attrs={'class': 'intro'}), |
| 27 |
dict(name='h3'), |
| 28 |
dict(name='div', attrs={'id': 'articlebody'}), |
| 29 |
] |
| 30 |
remove_tags_after = [dict(id='bodyText')] |
| 31 |
remove_tags = [ |
| 32 |
dict(name='li'), |
| 33 |
dict(attrs={'class': 'grid-4 right-hand-column'}), |
| 34 |
] |
| 35 |
|
| 36 |
feeds = [ |
| 37 |
('News', 'http://www.thesun.co.uk/sol/homepage/news/rss'), |
| 38 |
('Sport', 'http://www.thesun.co.uk/sol/homepage/sport/rss'), |
| 39 |
('Showbiz', 'http://www.thesun.co.uk/sol/homepage/showbiz/rss'), |
| 40 |
('Woman', 'http://www.thesun.co.uk/sol/homepage/woman/rss'), |
| 41 |
] |
| 42 |
# starsons code |
| 43 |
|
| 44 |
def parse_feeds(self): |
| 45 |
feeds = BasicNewsRecipe.parse_feeds(self) |
| 46 |
for feed in feeds: |
| 47 |
for article in feed.articles[:]: |
| 48 |
if 'Try out The Sun' in article.title.upper() or 'Try-out-The-Suns' in article.url: |
| 49 |
feed.articles.remove(article) |
| 50 |
if 'Web porn harms kids' in article.title.upper() or 'Sun-says-Web-porn' in article.url: |
| 51 |
feed.articles.remove(article) |
| 52 |
return feeds |
| 53 |
|
| 54 |
def get_cover_url(self): |
| 55 |
br = browser() |
| 56 |
br.set_handle_redirect(False) |
| 57 |
cover_url = 'http://www.thepaperboy.com/frontpages/current/The_Sun_newspaper_front_page.jpg' |
| 58 |
|
| 59 |
try: |
| 60 |
br.open_novisit('http://www.thepaperboy.com/frontpages/current/The_Sun_newspaper_front_page.jpg') |
| 61 |
except Exception: |
| 62 |
cover_url = random.choice([ |
| 63 |
'http://img.thesun.co.uk/multimedia/archive/00905/errorpage6_677961a_905507a.jpg', |
| 64 |
'http://img.thesun.co.uk/multimedia/archive/00905/errorpage7_677962a_905505a.jpg', |
| 65 |
'http://img.thesun.co.uk/multimedia/archive/00905/errorpage5_677960a_905512a.jpg', |
| 66 |
'http://img.thesun.co.uk/multimedia/archive/00905/errorpage2_677957a_905502a.jpg', |
| 67 |
'http://img.thesun.co.uk/multimedia/archive/00905/errorpage3_677958a_905503a.jpg', # noqa: E501 |
| 68 |
]) |
| 69 |
|
| 70 |
return cover_url |