| 1 |
# Copyright (C) 2008 B.Scott Wxby [bswxby] & |
| 2 |
# Copyright (C) 2007 David Chen SonyReader<at>DaveChen<dot>org |
| 3 |
## |
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
## |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
## |
| 14 |
# Version 0.3-2008_2_28 |
| 15 |
# Based on WIRED.py by David Chen, 2007, and newsweek.py, bbc.py, nytimes.py by Kovid Goyal |
| 16 |
## |
| 17 |
# Usage: |
| 18 |
# >web2lrf --user-profile nasa.py |
| 19 |
# Comment out the RSS feeds you don't want in the last section below |
| 20 |
## |
| 21 |
# Output: |
| 22 |
# NASA [YearMonthDate Time].lrf |
| 23 |
## |
| 24 |
""" |
| 25 |
Custom User Profile to download RSS News Feeds and Articles from Wired.com |
| 26 |
""" |
| 27 |
|
| 28 |
import re |
| 29 |
|
| 30 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 31 |
|
| 32 |
|
| 33 |
class NASA(BasicNewsRecipe): |
| 34 |
title = 'NASA' |
| 35 |
timefmt = ' [%Y%b%d %H%M]' |
| 36 |
language = 'en' |
| 37 |
|
| 38 |
description = 'News from NASA' |
| 39 |
__author__ = 'Scott Wxby & David Chen' |
| 40 |
no_stylesheets = True |
| 41 |
|
| 42 |
# Don't grab articles more than 30 days old |
| 43 |
oldest_article = 30 |
| 44 |
|
| 45 |
preprocess_regexps = [ |
| 46 |
(re.compile(i[0], re.IGNORECASE | re.DOTALL), i[1]) |
| 47 |
for i in [ |
| 48 |
# Fix the encoding to UTF-8 |
| 49 |
(r'<meta http-equiv="Content-Type" content="text/html; charset=(\S+)"', lambda match: match.group().replace(match.group(1), 'UTF-8')), |
| 50 |
# Remove any banners/links/ads/cruft before the body of the article. |
| 51 |
( |
| 52 |
r'<body.*?((<div id="article_body">)|(<div id="st-page-maincontent">)|(<div id="containermain">)|(<p class="ap-story-p">)|(<!-- img_nav -->))', |
| 53 |
lambda match: '<body><div>', |
| 54 |
), # noqa: E501 |
| 55 |
# Remove any links/ads/comments/cruft from the end of the body |
| 56 |
# of the article. |
| 57 |
( |
| 58 |
( |
| 59 |
r'((<!-- end article content -->)|(<div id="st-custom-afterpagecontent">)' |
| 60 |
r'|(<p class="ap-story-p">©)|(<div class="entry-footer">)' |
| 61 |
r'|(<div id="see_also">)|(<p>Via <a href=)|(<div id="ss_nav">)).*?</html>' |
| 62 |
), |
| 63 |
lambda match: '</div></body></html>', |
| 64 |
), |
| 65 |
# Correctly embed in-line images by removing the surrounding |
| 66 |
# javascript that will be ignored in the conversion |
| 67 |
( |
| 68 |
r'<a.*?onclick.*?>.*?(<img .*?>)', |
| 69 |
lambda match: match.group(1), |
| 70 |
), |
| 71 |
# This removes header and footer information from each print |
| 72 |
# version. |
| 73 |
(r'<!-- Top Header starts -->.*?<!-- Body starts -->', lambda match: '<New Stuff>'), |
| 74 |
(r'<hr align="center" width="200"><p align="center">.*?<!-- Press Release standard text ends -->', lambda match: '<New Stuff>'), |
| 75 |
(r'<!-- Top Header starts -->.*?<!---->', lambda match: '<New Stuff>'), |
| 76 |
# This removes the "download image" of various sizes from the Image of |
| 77 |
# the day. |
| 78 |
(r'<div id="download_image_box_print">.*?<div id="caption_region_print">', lambda match: '<New Stuff>'), |
| 79 |
] |
| 80 |
] |
| 81 |
|
| 82 |
# NASA's print pages differ only by the ending "_prt.htm", so I've |
| 83 |
# replaced them below. |
| 84 |
|
| 85 |
def print_version(self, url): |
| 86 |
return url.replace('.html', '_prt.htm') |
| 87 |
|
| 88 |
# Comment out the feeds you don't want retrieved. |
| 89 |
# Or add any new new RSS feed URL's here, sorted alphabetically when converted to LRF |
| 90 |
# If you want one of these at the top, append a space in front of the name. |
| 91 |
# Mars feed may not work, as it is now considered "legacy" by NASA. |
| 92 |
|
| 93 |
feeds = [ |
| 94 |
(' Breaking News', 'https://www.nasa.gov/rss/dyn/breaking_news.rss'), |
| 95 |
('Image of the Day', 'https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss'), |
| 96 |
('Mars Exploration', 'https://marsmobile.jpl.nasa.gov/rss/?feed=news&category=all'), |
| 97 |
('Shuttle and Station News', 'https://www.nasa.gov/rss/dyn/shuttle_station.rss'), |
| 98 |
('Solar System and Beyond News', 'https://www.nasa.gov/rss/dyn/solar_system.rss'), |
| 99 |
('Education News', 'https://www.nasa.gov/rss/dyn/educationnews.rss'), |
| 100 |
('Earth News', 'https://www.nasa.gov/rss/dyn/earth.rss'), |
| 101 |
('Aeronautics News', 'https://www.nasa.gov/rss/dyn/aeronautics.rss'), |
| 102 |
] |