From ac089c444df7861545d36d251bc904316ce0991a Mon Sep 17 00:00:00 2001 From: unkn0w7n <51942695+unkn0w7n@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:23:25 +0530 Subject: [PATCH] World Archaeology Magazine --- recipes/icons/world_archeology.png | Bin 0 -> 382 bytes recipes/military_history.recipe | 9 +-- recipes/world_archeology.recipe | 100 +++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 recipes/icons/world_archeology.png create mode 100644 recipes/world_archeology.recipe diff --git a/recipes/icons/world_archeology.png b/recipes/icons/world_archeology.png new file mode 100644 index 0000000000000000000000000000000000000000..39a11410c8a3bdbe30d16c4065570962b9da5294 GIT binary patch literal 382 zcmV-^0fGLBP)+yt% zr_|Qr00UE)oU*2=z5oeSM^1ap&f9Ktlr%kXEH`Zc094@N=>Pynprf?_09Wtu^tQRk ztF66NTZBteep+9I002NdM00d`l;W&<)c^nhxJg7oR2Y?Ik8N**Fc5>!mp2j;0!=A} zwvBo#54Xf#PlHS4Nal5KZL$Nn_9^Eg!n zyC7U~8|OPDvMq(ByA8O^;sJ)&MA|zYXC<(AYMo;VoUgU(u^!yAVfYDbPH7yoZ&7}z z3u0RM4Ixe9qahP;G*6s*JjIG&3WM~D2oo$m-B#{4yMO6?-ZL-pt2CGz+mK|oEU7a5 cKJNegZ*Er#c3AY%mjD0&07*qoM6N<$f*9MLvH$=8 literal 0 HcmV?d00001 diff --git a/recipes/military_history.recipe b/recipes/military_history.recipe index 46882e27f9..3f6565e611 100644 --- a/recipes/military_history.recipe +++ b/recipes/military_history.recipe @@ -57,10 +57,11 @@ class milthist(BasicNewsRecipe): if dt: self.timefmt = ' [' + self.tag_to_string(dt).strip() + ']' edit = issue.find('h2', attrs={'id':'from-the-editor'}) - if edit.findNext('p'): - self.description = self.tag_to_string(edit.findNext('p')) - if edit.findPrevious('figure'): - self.cover_url = edit.findPrevious('figure').img['src'] + if edit and edit.findParent('div'): + self.description = self.tag_to_string(edit.findParent('div')) + cov = issue.find('figure', attrs={'class':lambda x: x and 'wp-block-image' in x.split()}) + if cov: + self.cover_url = cov.img['src'] div = issue.find('div', attrs={'class':lambda x: x and 'entry-content' in x.split()}) feeds = [] diff --git a/recipes/world_archeology.recipe b/recipes/world_archeology.recipe new file mode 100644 index 0000000000..9a17b1e75a --- /dev/null +++ b/recipes/world_archeology.recipe @@ -0,0 +1,100 @@ +''' +https://www.world-archaeology.com +''' +from calibre import browser +from calibre.web.feeds.news import BasicNewsRecipe + +class worldarch(BasicNewsRecipe): + title = 'Current World Archaeology' + language = 'en' + __author__ = 'unkn0wn' + description = ( + 'Travel the globe with Current World Archaeology, the magazine that brings you up-to-date with the latest archaeological discoveries. ' + 'Explore sites – and sights – through our exclusive features and eye-popping photography. We bring you the stories from the ' + 'archaeologists themselves, so you learn first-hand from the experts about the latest finds and most up-to-date research. ' + 'Published six times a year.' + ) + no_stylesheets = True + use_embedded_content = False + remove_attributes = ['style', 'height', 'width'] + ignore_duplicate_articles = {'url'} + resolve_internal_links = True + masthead_url = 'https://i0.wp.com/www.world-archaeology.com/wp-content/uploads/2016/02/cwa-logo.png' + simultaneous_downloads = 1 + + extra_css = ''' + [class^="meta"] { font-size:small; } + .post-subtitle { font-style: italic; color:#202020; } + .wp-block-image { font-size:small; text-align:center; } + ''' + + keep_only_tags = [ + dict(attrs={'class':lambda x: x and '__header' in x}), + dict(attrs={'class':lambda x: x and '__background' in x}), + dict(attrs={'class':lambda x: x and '__body_area' in x}), + ] + + remove_tags = [ + dict(attrs={'class':'ad-break'}), + dict(attrs={'class':lambda x: x and 'avatar' in x.split()}), + dict(attrs={'class':lambda x: x and '--share' in x}) + ] + + def preprocess_html(self, soup): + exp = soup.find(attrs={'class':lambda x: x and 'post-subtitle' in x.split()}) + if exp: + exp.name = 'p' + return soup + + def parse_index(self): + soup = self.index_to_soup('https://the-past.com/category/magazines/cwa/') + art = soup.find('article', attrs={'class':lambda x: x and 'tag-magazines' in x.split()}) + url = art.h2.a['href'] + + # for past editions, add url + # url = '' + + issue = self.index_to_soup(url) + dt = soup.find(attrs={'class':lambda x: x and '__date' in x}) + if dt: + self.timefmt = ' [' + self.tag_to_string(dt).strip() + ']' + edit = issue.find('h2', attrs={'id':'from-the-editor'}) + if edit and edit.findParent('div'): + self.description = self.tag_to_string(edit.findParent('div')) + cov = issue.find('figure', attrs={'class':lambda x: x and 'wp-block-image' in x.split()}) + if cov: + self.cover_url = cov.img['src'] + div = issue.find('div', attrs={'class':lambda x: x and 'entry-content' in x.split()}) + + feeds = [] + + h2 = div.findAll('h2', attrs={'class':lambda x: x and 'wp-block-heading' in x.split()}) + lt = div.findAll(attrs={'class':'display-posts-listing'}) + for x, y in zip(h2, lt): + section = self.tag_to_string(x).strip() + self.log(section) + articles = [] + for a in y.findAll('a', href=True, attrs={'class':'title'}): + url = a['href'] + title = self.tag_to_string(a).strip() + desc = '' + exp = a.findNext(attrs={'class':'excerpt'}) + if exp: + desc = self.tag_to_string(exp).strip() + self.log('\t', title, '\n\t', desc, '\n\t\t', url) + articles.append({'title': title, 'description':desc, 'url': url}) + if articles: + feeds.append((section, articles)) + return feeds + + def get_browser(self, *args, **kwargs): + return self + + def clone_browser(self, *args, **kwargs): + return self.get_browser() + + def open_novisit(self, *args, **kwargs): + br = browser() + return br.open_novisit(*args, **kwargs) + + open = open_novisit