| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
from __future__ import absolute_import, division, print_function, unicode_literals |
| 4 |
|
| 5 |
import re |
| 6 |
import shutil |
| 7 |
|
| 8 |
try: |
| 9 |
from urllib.parse import urlencode |
| 10 |
except ImportError: |
| 11 |
from urllib import urlencode |
| 12 |
from calibre.ptempfile import PersistentTemporaryDirectory, PersistentTemporaryFile |
| 13 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 14 |
|
| 15 |
|
| 16 |
class AdvancedUserRecipe1515196393(BasicNewsRecipe): |
| 17 |
title = "The Galaxy's Edge" |
| 18 |
__author__ = 'andyh2000' |
| 19 |
delay = 2 |
| 20 |
oldest_article = 7 |
| 21 |
max_articles_per_feed = 100 |
| 22 |
auto_cleanup = True |
| 23 |
language = 'en' |
| 24 |
encoding = 'utf8' |
| 25 |
no_stylesheets = True |
| 26 |
|
| 27 |
extra_css = '.photo-caption { font-size: smaller }' |
| 28 |
|
| 29 |
def parse_index(self): |
| 30 |
soup = self.index_to_soup('http://www.galaxysedge.com/') |
| 31 |
cover_image = soup.find('div', attrs={'class': 'ci-img'}) |
| 32 |
cover_image = cover_image.find('img') |
| 33 |
self.cover_url = cover_image['src'] |
| 34 |
issue_title = soup.find('h1') |
| 35 |
self.title = "Galaxy's Edge: " + self.tag_to_string(issue_title).lower().title() |
| 36 |
toc = soup.find('div', attrs={'class': 'nav-tabs'}) |
| 37 |
current_section = 'Articles' |
| 38 |
current_articles = [] |
| 39 |
feeds = [] |
| 40 |
br = self.get_browser() |
| 41 |
self.ctdir = PersistentTemporaryDirectory() |
| 42 |
for x in toc.findAll(['li'], attrs={'class': re.compile(r'.*get_content.*')}): |
| 43 |
edwo = x.find('a') |
| 44 |
title = self.tag_to_string(edwo) |
| 45 |
self.log('\t\tFound article:', title) |
| 46 |
post_id = x['data-post-id'] |
| 47 |
cat_id = x['data-cat-id'] |
| 48 |
parent_id = x['data-parent-id'] |
| 49 |
self.log('\t\tdata-parent-id', parent_id) |
| 50 |
self.log('\t\tdata-cat-id', cat_id) |
| 51 |
self.log('\t\tdata-post-id', post_id) |
| 52 |
data = urlencode({'action': 'get_content', 'cat_id': cat_id, 'parent_id': parent_id, 'post_id': post_id}) |
| 53 |
r = br.open('http://www.galaxysedge.com/wp-content/themes/galaxyedge/get_content.php', data) |
| 54 |
content_file = PersistentTemporaryFile(suffix='.html', dir=self.ctdir) |
| 55 |
content_file.write(r.read()) |
| 56 |
content_file.close() |
| 57 |
current_articles.append({'title': title, 'url': 'file://' + content_file.name, 'description': '', 'date': ''}) |
| 58 |
if current_articles and current_section: |
| 59 |
feeds.append((current_section, current_articles)) |
| 60 |
|
| 61 |
return feeds |
| 62 |
|
| 63 |
def cleanup(self): |
| 64 |
self.log('Deleting temp files...') |
| 65 |
shutil.rmtree(self.ctdir) |