mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update The Galaxy's Edge
This commit is contained in:
parent
1870bc10fa
commit
22ef5f166b
@ -1,67 +1,62 @@
|
|||||||
from __future__ import with_statement
|
#!/usr/bin/env python2
|
||||||
__license__ = 'GPL 3'
|
# vim:fileencoding=utf-8
|
||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import urllib
|
||||||
|
|
||||||
|
from calibre.ptempfile import PersistentTemporaryDirectory, PersistentTemporaryFile
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
|
||||||
|
|
||||||
class GalaxyEdge(BasicNewsRecipe):
|
class AdvancedUserRecipe1515196393(BasicNewsRecipe):
|
||||||
title = u'The Galaxy\'s Edge'
|
title = "The Galaxy's Edge"
|
||||||
language = 'en'
|
__author__ = 'andyh2000'
|
||||||
|
delay = 2
|
||||||
oldest_article = 7
|
oldest_article = 7
|
||||||
__author__ = 'Krittika Goyal'
|
max_articles_per_feed = 100
|
||||||
|
auto_cleanup = True
|
||||||
|
language = 'en'
|
||||||
|
encoding = 'utf8'
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
|
|
||||||
auto_cleanup = True
|
|
||||||
|
|
||||||
extra_css = '.photo-caption { font-size: smaller }'
|
extra_css = '.photo-caption { font-size: smaller }'
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
soup = self.index_to_soup('http://www.galaxysedge.com/')
|
soup = self.index_to_soup('http://www.galaxysedge.com/')
|
||||||
main = soup.find('table', attrs={'width': '944'})
|
cover_image = soup.find('div', attrs={'class':'ci-img'})
|
||||||
toc = main.find('td', attrs={'width': '204'})
|
cover_image = cover_image.find('img')
|
||||||
|
self.cover_url = cover_image['src']
|
||||||
current_section = None
|
issue_title = soup.find('h1')
|
||||||
|
self.title = "Galaxy's Edge: " + self.tag_to_string(issue_title).lower().title()
|
||||||
|
toc = soup.find('div', attrs={'class':'nav-tabs'})
|
||||||
|
current_section = "Articles"
|
||||||
current_articles = []
|
current_articles = []
|
||||||
feeds = []
|
feeds = []
|
||||||
c = 0
|
br = self.get_browser()
|
||||||
for x in toc.findAll(['p']):
|
self.ctdir = PersistentTemporaryDirectory()
|
||||||
c = c + 1
|
for x in toc.findAll(['li'], attrs={"class": re.compile(".*get_content.*")}):
|
||||||
if c == 5:
|
edwo = x.find('a')
|
||||||
if current_articles and current_section:
|
title = self.tag_to_string(edwo)
|
||||||
feeds.append((current_section, current_articles))
|
self.log('\t\tFound article:', title)
|
||||||
edwo = x.find('a')
|
post_id = x["data-post-id"]
|
||||||
current_section = self.tag_to_string(edwo)
|
cat_id = x["data-cat-id"]
|
||||||
current_articles = []
|
parent_id = x["data-parent-id"]
|
||||||
self.log('\tFound section:', current_section)
|
self.log('\t\tdata-parent-id', parent_id)
|
||||||
title = self.tag_to_string(edwo)
|
self.log('\t\tdata-cat-id', cat_id)
|
||||||
url = edwo.get('href', True)
|
self.log('\t\tdata-post-id', post_id)
|
||||||
url = 'http://www.galaxysedge.com/' + url
|
data = urllib.urlencode({'action':'get_content', 'cat_id':cat_id, 'parent_id':parent_id, 'post_id':post_id})
|
||||||
print(title)
|
r=br.open('http://www.galaxysedge.com/wp-content/themes/galaxyedge/get_content.php', data)
|
||||||
print(c)
|
content_file = PersistentTemporaryFile(suffix='.html', dir=self.ctdir)
|
||||||
if not url or not title:
|
content_file.write(r.read())
|
||||||
continue
|
content_file.close()
|
||||||
self.log('\t\tFound article:', title)
|
current_articles.append({'title': title, 'url':'file://' + content_file.name, 'description':'', 'date':''})
|
||||||
self.log('\t\t\t', url)
|
if current_articles and current_section:
|
||||||
current_articles.append({'title': title, 'url': url,
|
feeds.append((current_section, current_articles))
|
||||||
'description': '', 'date': ''})
|
|
||||||
elif c > 5:
|
|
||||||
current_section = self.tag_to_string(x.find('b'))
|
|
||||||
current_articles = []
|
|
||||||
self.log('\tFound section:', current_section)
|
|
||||||
for y in x.findAll('a'):
|
|
||||||
title = self.tag_to_string(y)
|
|
||||||
url = y.get('href', True)
|
|
||||||
url = 'http://www.galaxysedge.com/' + url
|
|
||||||
print(title)
|
|
||||||
if not url or not title:
|
|
||||||
continue
|
|
||||||
self.log('\t\tFound article:', title)
|
|
||||||
self.log('\t\t\t', url)
|
|
||||||
current_articles.append({'title': title, 'url': url,
|
|
||||||
'description': '', 'date': ''})
|
|
||||||
if current_articles and current_section:
|
|
||||||
feeds.append((current_section, current_articles))
|
|
||||||
|
|
||||||
return feeds
|
return feeds
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
self.log("Deleting temp files...")
|
||||||
|
shutil.rmtree(self.ctdir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user