| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 4 |
|
| 5 |
|
| 6 |
class Diplomat(BasicNewsRecipe): |
| 7 |
title = 'The Diplomat' |
| 8 |
description = 'The Diplomat is the premier international current-affairs magazine for the Asia-Pacific region. READ THE DIPLOMAT, KNOW THE ASIA-PACIFIC' |
| 9 |
language = 'en' |
| 10 |
__author__ = 'unkn0wn' |
| 11 |
oldest_article = 14 # days |
| 12 |
max_articles_per_feed = 100 |
| 13 |
encoding = 'utf-8' |
| 14 |
use_embedded_content = False |
| 15 |
no_stylesheets = True |
| 16 |
remove_attributes = ['style', 'height', 'width'] |
| 17 |
masthead_url = 'https://thediplomat.com/wp-content/themes/td_theme_v3/assets/logo/diplomat_logo_black.svg' |
| 18 |
ignore_duplicate_articles = {'url'} |
| 19 |
extra_css = ''' |
| 20 |
#td-meta { font-size: x-small } |
| 21 |
#td-story-authors { font-size: small} |
| 22 |
#td-story-image{font-size: small; font-style: italic;} |
| 23 |
[id^="caption-attachment"] {font-size: small; font-style: italic;} |
| 24 |
''' |
| 25 |
|
| 26 |
def get_cover_url(self): |
| 27 |
soup = self.index_to_soup('https://thediplomat.com') |
| 28 |
tag = soup.find(attrs={'class': 'td-nav-mag'}) |
| 29 |
if tag: |
| 30 |
url = tag.find('img')['src'].split('/')[-1] |
| 31 |
self.cover_url = 'https://magazine.thediplomat.com/media/1080/' + url |
| 32 |
# /ads/magazine/cover/td-mag-s-1/issue_89_cover.jpg |
| 33 |
# https://magazine.thediplomat.com/media/1080/issue_89_cover.jpg |
| 34 |
return super().get_cover_url() |
| 35 |
|
| 36 |
keep_only_tags = [ |
| 37 |
dict(name='header', attrs={'id': 'td-story-head'}), |
| 38 |
classes('td-media--story td-prose td-story-magazine__link td-authors'), |
| 39 |
] |
| 40 |
|
| 41 |
remove_tags = [ |
| 42 |
dict(name='aside', attrs={'id': 'td-box-newsletter'}), |
| 43 |
classes('td-share td-ad td-ad-inline-txt'), |
| 44 |
] |
| 45 |
|
| 46 |
feeds = [ |
| 47 |
('Features', 'https://thediplomat.com/category/features/feed'), |
| 48 |
('Interviews', 'https://thediplomat.com/category/interviews/feed'), |
| 49 |
('Magazine Preview', 'https://thediplomat.com/category/magazine/feed'), |
| 50 |
# REGIONS |
| 51 |
('Central Asia', 'https://thediplomat.com/regions/central-asia/feed'), |
| 52 |
('East Asia', 'https://thediplomat.com/regions/east-asia/feed'), |
| 53 |
('Oceania', 'https://thediplomat.com/regions/oceania-region/feed'), |
| 54 |
('South Asia', 'https://thediplomat.com/regions/south-asia/feed'), |
| 55 |
('South East Asia', 'https://thediplomat.com/regions/southeast-asia/feed'), |
| 56 |
# TOPICS |
| 57 |
('Diplomacy', 'https://thediplomat.com/topics/diplomacy/feed'), |
| 58 |
('Economy', 'https://thediplomat.com/topics/economy/feed'), |
| 59 |
('Environment', 'https://thediplomat.com/topics/environment/feed'), |
| 60 |
('Opinion', 'https://thediplomat.com/topics/opinion/feed'), |
| 61 |
('Politics', 'https://thediplomat.com/topics/politics/feed'), |
| 62 |
('Security', 'https://thediplomat.com/topics/security/feed'), |
| 63 |
('Society', 'https://thediplomat.com/topics/society/feed'), |
| 64 |
] |
| 65 |
|
| 66 |
def preprocess_html(self, soup): |
| 67 |
for img in soup.findAll('img', attrs={'src': True}): |
| 68 |
img['src'] = img['src'].replace('td-story-s-1', 'td-story-s-2') |
| 69 |
return soup |