| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
__license__ = 'GPL v3' |
| 4 |
__copyright__ = '2008, Darko Miletic <darko.miletic at gmail.com>' |
| 5 |
''' |
| 6 |
sfgate.com |
| 7 |
''' |
| 8 |
|
| 9 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 10 |
|
| 11 |
|
| 12 |
class SanFranciscoChronicle(BasicNewsRecipe): |
| 13 |
title = 'San Francisco Chronicle' |
| 14 |
__author__ = 'Kovid Goyal' |
| 15 |
description = 'San Francisco news' |
| 16 |
language = 'en_US' |
| 17 |
|
| 18 |
oldest_article = 7 |
| 19 |
max_articles_per_feed = 20 |
| 20 |
no_stylesheets = True |
| 21 |
use_embedded_content = False |
| 22 |
delay = 1 |
| 23 |
|
| 24 |
extra_css = ''' |
| 25 |
h1{font-family :Arial,Helvetica,sans-serif; font-size:large;} |
| 26 |
h2{font-family :Arial,Helvetica,sans-serif; font-size:medium; color:#666666;} |
| 27 |
h3{font-family :Arial,Helvetica,sans-serif; font-size:medium; color:#000000;} |
| 28 |
h4{font-family :Arial,Helvetica,sans-serif; font-size: x-small;} |
| 29 |
p{font-family :Arial,Helvetica,sans-serif; font-size:x-small;} |
| 30 |
.byline{font-family :Arial,Helvetica,sans-serif; font-size: xx-small;} |
| 31 |
.date{font-family :Arial,Helvetica,sans-serif; font-size: xx-small;} |
| 32 |
.dtlcomment{font-style:italic;} |
| 33 |
.georgia h3{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#000000;} |
| 34 |
''' |
| 35 |
keep_only_tags = [ |
| 36 |
dict(name='h1'), |
| 37 |
dict(**classes('package')), |
| 38 |
] |
| 39 |
remove_tags = [ |
| 40 |
dict(id=['badge-logo', 'everlit-auto-audio-widget']), |
| 41 |
dict(name='svg'), |
| 42 |
dict(attrs={'data-eid': lambda x: x and ('news_alert_bar' in x or 'card' in x or 'mostPopular' in x or 'dynamic_thumbnail_list' in x)}), |
| 43 |
dict(href=lambda x: x and 'california-mini-crossword' in x), |
| 44 |
dict(attrs={'data-block-type': 'embed'}), |
| 45 |
dict(name='img', width='1'), |
| 46 |
] |
| 47 |
|
| 48 |
feeds = [ |
| 49 |
('Bay Area News', 'https://www.sfgate.com/bayarea/feed/Bay-Area-News-429.php'), |
| 50 |
('City Insider', 'https://www.sfgate.com/default/feed/City-Insider-Blog-573.php'), |
| 51 |
('Crime Scene', 'https://www.sfgate.com/rss/feed/Crime-Scene-Blog-599.php'), |
| 52 |
('Education News', 'https://www.sfgate.com/education/feed/Education-News-from-SFGate-430.php'), |
| 53 |
('National News', 'https://www.sfgate.com/rss/feed/National-News-RSS-Feed-435.php'), |
| 54 |
('Weird News', 'https://www.sfgate.com/weird/feed/Weird-News-RSS-Feed-433.php'), |
| 55 |
('World News', 'https://www.sfgate.com/rss/feed/World-News-From-SFGate-432.php'), |
| 56 |
] |
| 57 |
|
| 58 |
def preprocess_html(self, soup): |
| 59 |
for picture in soup.find_all('picture'): |
| 60 |
img = picture.find('img') |
| 61 |
if img: |
| 62 |
for i, source in enumerate(picture.find_all('source')): |
| 63 |
if i == 0: |
| 64 |
img['src'] = source['srcset'].split()[0] |
| 65 |
source.extract() |
| 66 |
return soup |