home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / nasa.recipe < prev    next >
Text File  |  2011-09-09  |  4KB  |  88 lines

  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. import re
  28. from calibre.web.feeds.news import BasicNewsRecipe
  29. class NASA(BasicNewsRecipe):
  30.  
  31.     title = 'NASA'
  32.     timefmt  = ' [%Y%b%d  %H%M]'
  33.     language = 'en'
  34.  
  35.     description = 'News from NASA'
  36.     __author__ = 'Scott Wxby & David Chen'
  37.     no_stylesheets = True
  38.  
  39.     ## Don't grab articles more than 30 days old
  40.     oldest_article = 30
  41.  
  42.     preprocess_regexps = [(re.compile(i[0], re.IGNORECASE | re.DOTALL), i[1]) for i in
  43.         [
  44.         ## Fix the encoding to UTF-8
  45.         (r'<meta http-equiv="Content-Type" content="text/html; charset=(\S+)"', lambda match : match.group().replace(match.group(1), 'UTF-8')),
  46.  
  47.         ## Remove any banners/links/ads/cruft before the body of the article.
  48.         (r'<body.*?((<div id="article_body">)|(<div id="st-page-maincontent">)|(<div id="containermain">)|(<p class="ap-story-p">)|(<!-- img_nav -->))', lambda match: '<body><div>'),
  49.  
  50.         ## Remove any links/ads/comments/cruft from the end of the body of the article.
  51.         (r'((<!-- end article content -->)|(<div id="st-custom-afterpagecontent">)|(<p class="ap-story-p">©)|(<div class="entry-footer">)|(<div id="see_also">)|(<p>Via <a href=)|(<div id="ss_nav">)).*?</html>', lambda match : '</div></body></html>'),
  52.  
  53.         ## Correctly embed in-line images by removing the surrounding javascript that will be ignored in the conversion
  54.         (r'<a.*?onclick.*?>.*?(<img .*?>)', lambda match: match.group(1),),
  55.  
  56.         ## This removes header and footer information from each print version.
  57.            (r'<!-- Top Header starts -->.*?<!-- Body starts -->', lambda match : '<New Stuff>'),
  58.         (r'<hr align="center" width="200"><p align="center">.*?<!-- Press Release standard text ends -->', lambda match : '<New Stuff>'),
  59.         (r'<!-- Top Header starts -->.*?<!---->', lambda match : '<New Stuff>'),
  60.  
  61.         ## This removes the "download image" of various sizes from the Image of the day.
  62.         (r'<div id="download_image_box_print">.*?<div id="caption_region_print">', lambda match : '<New Stuff>'),
  63.  
  64.         ]
  65.     ]
  66.  
  67. ## NASA's print pages differ only by the ending "_prt.htm", so I've replaced them below.
  68.  
  69.     def print_version(self, url):
  70.         return url.replace('.html', '_prt.htm')
  71.  
  72. ## Comment out the feeds you don't want retrieved.
  73. ## Or add any new new RSS feed URL's here, sorted alphabetically when converted to LRF
  74. ## If you want one of these at the top, append a space in front of the name.
  75.  
  76.  
  77.     feeds = [
  78.           (' Breaking News', 'http://www.nasa.gov/rss/breaking_news.rss'),
  79.         ('Image of the Day', 'http://www.nasa.gov/rss/image_of_the_day.rss'),
  80.         ('Moon and Mars Exploration', 'http://www.nasa.gov/rss/moon_mars.rss'),
  81.         ('Shuttle and Station News', 'http://www.nasa.gov/rss/shuttle_station.rss'),
  82.         ('Solar System News', 'http://www.nasa.gov/rss/solar_system.rss'),
  83.         ('Universe News', 'http://www.nasa.gov/rss/universe.rss'),
  84.         ('Earth News', 'http://www.nasa.gov/rss/earth.rss'),
  85.         ('Aeronautics News', 'http://www.nasa.gov/rss/aeronautics.rss'),
  86.         ]
  87.  
  88.