mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update LWN
This commit is contained in:
parent
58abe77cbc
commit
ef4b098411
@ -1,53 +1,64 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = 'Chris Moore 2025'
|
||||||
'''
|
__version__ = '1.0'
|
||||||
lwn.net
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from calibre import walk
|
||||||
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
|
from calibre.utils.zipfile import ZipFile
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
|
||||||
|
|
||||||
class LWN(BasicNewsRecipe):
|
class lwn_epub(BasicNewsRecipe):
|
||||||
title = u'lwn'
|
__author__ = 'Chris Moore'
|
||||||
__author__ = 'Oliver Niesner'
|
title = 'lwn'
|
||||||
description = 'Linux Weekly News'
|
|
||||||
oldest_article = 54
|
|
||||||
max_articles_per_feed = 100
|
|
||||||
needs_subscription = True
|
|
||||||
language = 'en'
|
language = 'en'
|
||||||
remove_javascript = True
|
publisher = 'lwn.net'
|
||||||
simultaneous_downloads = 1
|
publication_type = 'magazine'
|
||||||
delay = 1
|
description = 'The weekly subscriber-only edition from Linux Weekly News'
|
||||||
LOGIN = 'https://lwn.net/login'
|
needs_subscription = True
|
||||||
|
|
||||||
|
conversion_options = {
|
||||||
|
'publisher': publisher, 'language': language, 'comments': description, 'no_default_epub_cover': True,
|
||||||
|
'preserve_cover_aspect_ratio': True
|
||||||
|
}
|
||||||
|
|
||||||
|
def build_index(self):
|
||||||
|
browser = self.get_browser()
|
||||||
|
browser.open('https://lwn.net/current')
|
||||||
|
|
||||||
|
# find the link
|
||||||
|
epublink = browser.find_link(text='Download EPUB')
|
||||||
|
|
||||||
|
# download ebook
|
||||||
|
self.report_progress(0, _('Downloading ePUB'))
|
||||||
|
response = browser.follow_link(epublink)
|
||||||
|
book_file = PersistentTemporaryFile(suffix='.epub')
|
||||||
|
book_file.write(response.read())
|
||||||
|
book_file.close()
|
||||||
|
|
||||||
|
# convert
|
||||||
|
self.report_progress(0.2, _('Converting to OEB'))
|
||||||
|
oeb = self.output_dir + '/INPUT/'
|
||||||
|
if not os.path.exists(oeb):
|
||||||
|
os.makedirs(oeb)
|
||||||
|
with ZipFile(book_file.name) as f:
|
||||||
|
f.extractall(path=oeb)
|
||||||
|
|
||||||
|
for f in walk(oeb):
|
||||||
|
if f.endswith('.opf'):
|
||||||
|
return f
|
||||||
|
|
||||||
def get_browser(self):
|
def get_browser(self):
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
if self.username is not None and self.password is not None:
|
if self.username is not None and self.password is not None:
|
||||||
br.open(self.LOGIN)
|
br.open('https://lwn.net/login')
|
||||||
br.select_form(name='loginform')
|
br.select_form(name='loginform')
|
||||||
br['uname'] = self.username
|
br['uname'] = self.username
|
||||||
br['pword'] = self.password
|
br['pword'] = self.password
|
||||||
br.submit()
|
br.submit()
|
||||||
return br
|
return br
|
||||||
|
|
||||||
remove_tags = [
|
|
||||||
dict(name='td', attrs={'class': 'LeftColumn'}),
|
|
||||||
dict(name='td', attrs={'class': 'NavLink'}),
|
|
||||||
dict(name='div', attrs={'class': 'FormattedComment'}),
|
|
||||||
dict(name='td', attrs={'class': 'MCTopBanner'}),
|
|
||||||
dict(name='div', attrs={'class': 'CommentBox'})
|
|
||||||
]
|
|
||||||
|
|
||||||
feeds = [
|
|
||||||
(u'lwn', u'http://lwn.net/headlines/newrss'),
|
|
||||||
]
|
|
||||||
|
|
||||||
def postprocess_html(self, soup, first):
|
|
||||||
for tag in soup.findAll(name=['table', 'tr', 'td']):
|
|
||||||
tag.name = 'div'
|
|
||||||
return soup
|
|
||||||
|
|
||||||
def print_version(self, url):
|
|
||||||
return url.replace('rss', '?format=printable')
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user