| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
# |
| 4 |
from __future__ import absolute_import, division, print_function, unicode_literals |
| 5 |
|
| 6 |
__license__ = 'GPL v3' |
| 7 |
__copyright__ = '2020, Pat Stapleton <pat.stapleton at gmail.com>' |
| 8 |
''' |
| 9 |
Recipe for Independent Australia |
| 10 |
''' |
| 11 |
|
| 12 |
from calibre.web.feeds import Feed |
| 13 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 14 |
|
| 15 |
|
| 16 |
class IndependentAustralia(BasicNewsRecipe): |
| 17 |
title = 'Independent Australia' |
| 18 |
language = 'en_AU' |
| 19 |
__author__ = 'Pat Stapleton' |
| 20 |
description = ( |
| 21 |
'Independent Australia is a progressive journal focusing on politics, democracy, the environment, Australian history and Australian identity.' |
| 22 |
' It contains news and opinion from Australia and around the world.' |
| 23 |
) |
| 24 |
|
| 25 |
feeds = [ |
| 26 |
('Independent Australia', 'https://feeds.feedburner.com/IndependentAustralia'), |
| 27 |
] |
| 28 |
|
| 29 |
masthead_url = 'https://independentaustralia.net/t/2018/logo-2018-lg-h90.png' |
| 30 |
cover_url = 'https://independentaustralia.net/t/apple-touch-icon.png' |
| 31 |
# cover_margins = (0,20,'#000000') |
| 32 |
scale_news_images_to_device = True |
| 33 |
oldest_article = 7 # days |
| 34 |
max_articles_per_feed = 100 |
| 35 |
publication_type = 'newspaper' |
| 36 |
|
| 37 |
# auto_cleanup = True # enable this as a backup option if recipe stops working |
| 38 |
|
| 39 |
# use_embedded_content = False # if set to true will assume that all the article content is within the feed (i.e. won't try to fetch more data) |
| 40 |
|
| 41 |
no_stylesheets = True |
| 42 |
remove_javascript = True |
| 43 |
|
| 44 |
keep_only_tags = [dict(name='div', attrs={'class': 'art-display'})] # the article content is contained in |
| 45 |
|
| 46 |
# ************************************ |
| 47 |
# Clear out all the unwanted html tags: |
| 48 |
# ************************************ |
| 49 |
remove_tags = [{'name': ['meta', 'link', 'noscript', 'script', 'footer']}, {'attrs': {'class': ['tagFooter', 'noshow', 'panelSubscription', 'mt-2']}}] |
| 50 |
|
| 51 |
# ************************************ |
| 52 |
# Tidy up the output to look neat for reading |
| 53 |
# ************************************ |
| 54 |
remove_attributes = ['width', 'height', 'style'] |
| 55 |
extra_css = '.byline{font-size:smaller;margin-bottom:10px;}.inline-caption{display:block;font-size:smaller;text-decoration: none;}' |
| 56 |
compress_news_images = True |
| 57 |
|
| 58 |
# ************************************ |
| 59 |
# Break up feed into categories (based on BrianG's code snippet): |
| 60 |
# ************************************ |
| 61 |
def parse_feeds(self): |
| 62 |
# Do the "official" parse_feeds first |
| 63 |
feeds = BasicNewsRecipe.parse_feeds(self) |
| 64 |
|
| 65 |
politicsArticles = [] |
| 66 |
environmentArticles = [] |
| 67 |
businessArticles = [] |
| 68 |
lifeArticles = [] |
| 69 |
australiaArticles = [] |
| 70 |
# Loop through the articles in all feeds to find articles with base categories in it |
| 71 |
for curfeed in feeds: |
| 72 |
delList = [] |
| 73 |
for a, curarticle in enumerate(curfeed.articles): |
| 74 |
if curarticle.url.lower().find('independentaustralia.net/politics/') >= 0: |
| 75 |
politicsArticles.append(curarticle) |
| 76 |
delList.append(curarticle) |
| 77 |
elif curarticle.url.lower().find('independentaustralia.net/environment/') >= 0: |
| 78 |
environmentArticles.append(curarticle) |
| 79 |
delList.append(curarticle) |
| 80 |
elif curarticle.url.lower().find('independentaustralia.net/business/') >= 0: |
| 81 |
businessArticles.append(curarticle) |
| 82 |
delList.append(curarticle) |
| 83 |
elif curarticle.url.lower().find('independentaustralia.net/life/') >= 0: |
| 84 |
lifeArticles.append(curarticle) |
| 85 |
delList.append(curarticle) |
| 86 |
elif curarticle.url.lower().find('independentaustralia.net/australia/') >= 0: |
| 87 |
australiaArticles.append(curarticle) |
| 88 |
delList.append(curarticle) |
| 89 |
if len(delList) > 0: |
| 90 |
for d in delList: |
| 91 |
index = curfeed.articles.index(d) |
| 92 |
curfeed.articles[index : index + 1] = [] |
| 93 |
|
| 94 |
# If there are any of each base category found, create, append a new Feed object |
| 95 |
if len(politicsArticles) > 0: |
| 96 |
pfeed = Feed() |
| 97 |
pfeed.title = 'Politics' |
| 98 |
pfeed.image_url = None |
| 99 |
pfeed.oldest_article = 30 |
| 100 |
pfeed.id_counter = len(politicsArticles) |
| 101 |
# Create a new Feed, add the articles, and append to "official" list of feeds |
| 102 |
pfeed.articles = politicsArticles[:] |
| 103 |
feeds.append(pfeed) |
| 104 |
if len(environmentArticles) > 0: |
| 105 |
pfeed = Feed() |
| 106 |
pfeed.title = 'Environment' |
| 107 |
pfeed.image_url = None |
| 108 |
pfeed.oldest_article = 30 |
| 109 |
pfeed.id_counter = len(environmentArticles) |
| 110 |
# Create a new Feed, add the articles, and append to "official" list of feeds |
| 111 |
pfeed.articles = environmentArticles[:] |
| 112 |
feeds.append(pfeed) |
| 113 |
if len(businessArticles) > 0: |
| 114 |
pfeed = Feed() |
| 115 |
pfeed.title = 'Business' |
| 116 |
pfeed.image_url = None |
| 117 |
pfeed.oldest_article = 30 |
| 118 |
pfeed.id_counter = len(businessArticles) |
| 119 |
# Create a new Feed, add the articles, and append to "official" list of feeds |
| 120 |
pfeed.articles = businessArticles[:] |
| 121 |
feeds.append(pfeed) |
| 122 |
if len(lifeArticles) > 0: |
| 123 |
pfeed = Feed() |
| 124 |
pfeed.title = 'Life' |
| 125 |
pfeed.image_url = None |
| 126 |
pfeed.oldest_article = 30 |
| 127 |
pfeed.id_counter = len(lifeArticles) |
| 128 |
# Create a new Feed, add the articles, and append to "official" list of feeds |
| 129 |
pfeed.articles = lifeArticles[:] |
| 130 |
feeds.append(pfeed) |
| 131 |
if len(australiaArticles) > 0: |
| 132 |
pfeed = Feed() |
| 133 |
pfeed.title = 'Australia' |
| 134 |
pfeed.image_url = None |
| 135 |
pfeed.oldest_article = 30 |
| 136 |
pfeed.id_counter = len(australiaArticles) |
| 137 |
# Create a new Feed, add the articles, and append to "official" list of feeds |
| 138 |
pfeed.articles = australiaArticles[:] |
| 139 |
feeds.append(pfeed) |
| 140 |
|
| 141 |
if len(feeds) > 1: # cleanup empty first feed item |
| 142 |
if len(feeds[0]) == 0: |
| 143 |
del feeds[0] |
| 144 |
return feeds |