| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
""" |
| 4 |
https://ancientegyptmagazine.com |
| 5 |
""" |
| 6 |
|
| 7 |
from calibre import browser |
| 8 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 9 |
|
| 10 |
|
| 11 |
class ancientegypt(BasicNewsRecipe): |
| 12 |
title = 'The Past: Ancient Egypt Magazine' |
| 13 |
language = 'en' |
| 14 |
__author__ = 'unkn0wn' |
| 15 |
description = ( |
| 16 |
"Ancient Egypt is the world's leading Egyptology magazine, exploring the history, people and culture of the Nile Valley. " |
| 17 |
'Now in a larger format with a fresh new design, AE brings you the latest news and discoveries, and feature articles covering ' |
| 18 |
'more than 5000 years of Egyptian history. Published bimonthly.' |
| 19 |
) |
| 20 |
no_stylesheets = True |
| 21 |
use_embedded_content = False |
| 22 |
remove_attributes = ['style', 'height', 'width'] |
| 23 |
ignore_duplicate_articles = {'url'} |
| 24 |
resolve_internal_links = True |
| 25 |
masthead_url = 'https://ancientegyptmagazine.com/media/website/ae-logo-2.png' |
| 26 |
simultaneous_downloads = 1 |
| 27 |
|
| 28 |
extra_css = ''' |
| 29 |
[class^="meta"], [class~="__author__text"], [class~="__date"] { font-size:small; } |
| 30 |
.post-subtitle { font-style: italic; color:#202020; } |
| 31 |
.wp-block-image { font-size:small; text-align:center; } |
| 32 |
''' |
| 33 |
|
| 34 |
keep_only_tags = [ |
| 35 |
dict( |
| 36 |
attrs={ |
| 37 |
'class': lambda x: ( |
| 38 |
x |
| 39 |
and any( |
| 40 |
tag in x |
| 41 |
for tag in [ |
| 42 |
'__image', |
| 43 |
'__header', |
| 44 |
'__background', |
| 45 |
'__body_area', |
| 46 |
'__author__text', |
| 47 |
'__date', |
| 48 |
] |
| 49 |
) |
| 50 |
) |
| 51 |
} |
| 52 |
) |
| 53 |
] |
| 54 |
|
| 55 |
remove_tags = [ |
| 56 |
dict(attrs={'class': 'ad-break'}), |
| 57 |
dict(attrs={'class': lambda x: x and any(cls in x.split() for cls in ['avatar', 'what-mag-row'])}), |
| 58 |
dict(attrs={'class': lambda x: x and '--share' in x}), |
| 59 |
] |
| 60 |
|
| 61 |
def preprocess_html(self, soup): |
| 62 |
for img in soup.findAll('img', attrs={'src': True}): |
| 63 |
if '?w=' in img['src']: |
| 64 |
res = '?w=600' |
| 65 |
w = self.recipe_specific_options.get('res') |
| 66 |
if w and isinstance(w, str): |
| 67 |
res = '?w=' + w |
| 68 |
img['src'] = img['src'].split('?')[0] + res |
| 69 |
img.attrs = {'src': img['src']} |
| 70 |
exp = soup.find(attrs={'class': lambda x: x and 'post-subtitle' in x.split()}) |
| 71 |
if exp: |
| 72 |
exp.name = 'p' |
| 73 |
return soup |
| 74 |
|
| 75 |
recipe_specific_options = { |
| 76 |
'issue': { |
| 77 |
'short': 'Enter the Issue Number you want to download ', |
| 78 |
'long': 'For example, 136', |
| 79 |
}, |
| 80 |
'res': { |
| 81 |
'short': 'For hi-res images, select a resolution from the\nfollowing options: 800, 1000, 1200 or 1500', |
| 82 |
'long': 'This is useful for non e-ink devices, and for a lower file size\nthan the default, use 400 or 300.', |
| 83 |
'default': '600', |
| 84 |
}, |
| 85 |
} |
| 86 |
|
| 87 |
def parse_index(self): |
| 88 |
soup = self.index_to_soup('https://the-past.com/category/magazines/ae/') |
| 89 |
art = soup.find('article', attrs={'class': lambda x: x and 'tag-magazines' in x.split()}) |
| 90 |
url = art.h2.a['href'] |
| 91 |
|
| 92 |
d = self.recipe_specific_options.get('issue') |
| 93 |
if d and isinstance(d, str): |
| 94 |
url = 'https://the-past.com/magazines/ae/ancient-egypt-magazine-' + d + '/' |
| 95 |
|
| 96 |
issue = self.index_to_soup(url) |
| 97 |
ti = issue.find('h1', attrs={'class': lambda x: x and 'post-title' in x.split()}) |
| 98 |
if ti: |
| 99 |
self.title = self.tag_to_string(ti).strip() |
| 100 |
dt = soup.find(attrs={'class': lambda x: x and '__date' in x}) |
| 101 |
if dt: |
| 102 |
self.timefmt = ' [' + self.tag_to_string(dt).strip() + ']' |
| 103 |
edit = issue.find('h2', attrs={'id': 'from-the-editor'}) |
| 104 |
if edit and edit.findParent('div'): |
| 105 |
self.description = self.tag_to_string(edit.findParent('div')) |
| 106 |
cov = issue.find('figure', attrs={'class': lambda x: x and 'wp-block-image' in x.split()}) |
| 107 |
if cov: |
| 108 |
self.cover_url = cov.img['src'].split('?')[0] + '?w=600' |
| 109 |
div = issue.find('div', attrs={'class': lambda x: x and 'entry-content' in x.split()}) |
| 110 |
|
| 111 |
feeds = [] |
| 112 |
|
| 113 |
h2 = div.findAll('h2', attrs={'class': lambda x: x and 'wp-block-heading' in x.split()}) |
| 114 |
lt = div.findAll(attrs={'class': 'display-posts-listing'}) |
| 115 |
for x, y in zip(h2, lt): |
| 116 |
section = self.tag_to_string(x).strip() |
| 117 |
self.log(section) |
| 118 |
articles = [] |
| 119 |
for a in y.findAll('a', href=True, attrs={'class': 'title'}): |
| 120 |
url = a['href'] |
| 121 |
title = self.tag_to_string(a).strip() |
| 122 |
desc = '' |
| 123 |
exp = a.findNext(attrs={'class': 'excerpt'}) |
| 124 |
if exp: |
| 125 |
desc = self.tag_to_string(exp).strip() |
| 126 |
self.log('\t', title, '\n\t', desc, '\n\t\t', url) |
| 127 |
articles.append({'title': title, 'description': desc, 'url': url}) |
| 128 |
if articles: |
| 129 |
feeds.append((section, articles)) |
| 130 |
return feeds |
| 131 |
|
| 132 |
def get_browser(self, *args, **kwargs): |
| 133 |
return self |
| 134 |
|
| 135 |
def clone_browser(self, *args, **kwargs): |
| 136 |
return self.get_browser() |
| 137 |
|
| 138 |
def open_novisit(self, *args, **kwargs): |
| 139 |
br = browser() |
| 140 |
return br.open_novisit(*args, **kwargs) |
| 141 |
|
| 142 |
open = open_novisit |