From 9e23a43f156c930a73ceeb66deca422a7933f7ee Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 25 Mar 2008 06:31:21 +0000 Subject: [PATCH] Add recipe for The BBC --- src/libprs500/web/feeds/recipes/__init__.py | 26 ++++++++++-- src/libprs500/web/feeds/recipes/bbc.py | 47 +++++++++++++++++++++ 2 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 src/libprs500/web/feeds/recipes/bbc.py diff --git a/src/libprs500/web/feeds/recipes/__init__.py b/src/libprs500/web/feeds/recipes/__init__.py index 650c1bd158..387393d881 100644 --- a/src/libprs500/web/feeds/recipes/__init__.py +++ b/src/libprs500/web/feeds/recipes/__init__.py @@ -18,15 +18,15 @@ Builtin recipes. ''' recipes = ['newsweek', 'atlantic', 'economist', 'dilbert', 'portfolio', - 'nytimes', 'usatoday', 'outlook_india'] + 'nytimes', 'usatoday', 'outlook_india', 'bbc'] import re, time -from libprs500.web.feeds.news import BasicNewsRecipe, CustomIndexRecipe +from libprs500.web.feeds.news import BasicNewsRecipe, CustomIndexRecipe, AutomaticNewsRecipe from libprs500.ebooks.lrf.web.profiles import DefaultProfile, FullContentProfile from libprs500.ebooks.lrf.web import builtin_profiles from libprs500.ebooks.BeautifulSoup import BeautifulSoup -basic_recipes = (BasicNewsRecipe, CustomIndexRecipe, DefaultProfile, FullContentProfile) +basic_recipes = (BasicNewsRecipe, AutomaticNewsRecipe, CustomIndexRecipe, DefaultProfile, FullContentProfile) basic_recipe_names = (i.__name__ for i in basic_recipes) @@ -87,4 +87,22 @@ def get_builtin_recipe(title): _titles = list(frozenset([r.title for r in recipes] + [p.title for p in builtin_profiles])) _titles.sort() -titles = _titles \ No newline at end of file +titles = _titles + +def migrate_automatic_profile_to_automatic_recipe(profile): + profile = compile_recipe(profile) + if 'BasicUserProfile' not in profile.__name__: + return profile + return '''\ +class BasicUserRecipe%d(AutomaticNewsRecipe): + + title = %s + oldest_article = %d + max_articles_per_feed = %d + summary_length = %d + + feeds = %s + +'''%(int(time.time()), repr(profile.title), profile.oldest_article, + profile.max_articles_per_feed, profile.summary_length, repr(profile.feeds)) + \ No newline at end of file diff --git a/src/libprs500/web/feeds/recipes/bbc.py b/src/libprs500/web/feeds/recipes/bbc.py new file mode 100644 index 0000000000..bf455cb6e8 --- /dev/null +++ b/src/libprs500/web/feeds/recipes/bbc.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +## Copyright (C) 2008 Kovid Goyal kovid@kovidgoyal.net +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License along +## with this program; if not, write to the Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +''' +bbc.co.uk +''' + +from libprs500.web.feeds.news import BasicNewsRecipe + +class BBC(BasicNewsRecipe): + title = u'The BBC' + no_stylesheets = True + + remove_tags = [dict(name='div', attrs={'class':'footer'})] + extra_css = '.headline {font-size: x-large;} \n .fact { padding-top: 10pt }' + + feeds = [ + ('News Front Page', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml'), + ('Science/Nature', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/science/nature/rss.xml'), + ('Technology', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/technology/rss.xml'), + ('Enterntainment', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/entertainment/rss.xml'), + ('Magazine', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/uk_news/magazine/rss.xml'), + ('Business', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/business/rss.xml'), + ('Health', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/health/rss.xml'), + ('Americas', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/americas/rss.xml'), + ('Europe', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/europe/rss.xml'), + ('South Asia', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/south_asia/rss.xml'), + ('UK', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/uk_news/rss.xml'), + ('Asia-Pacific', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/asia-pacific/rss.xml'), + ('Africa', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/africa/rss.xml'), + ] + + def print_version(self, url): + return url.replace('http://', 'http://newsvote.bbc.co.uk/mpapps/pagetools/print/') \ No newline at end of file