mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Make adding feeds to GUI automatic
This commit is contained in:
parent
3c3feea52d
commit
fd46312fcc
@ -13,3 +13,20 @@
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from libprs500.ebooks.lrf.web.profiles.nytimes import NYTimes
|
||||
from libprs500.ebooks.lrf.web.profiles.bbc import BBC
|
||||
from libprs500.ebooks.lrf.web.profiles.newsweek import Newsweek
|
||||
from libprs500.ebooks.lrf.web.profiles.economist import Economist
|
||||
from libprs500.ebooks.lrf.web.profiles.newyorkreview import NewYorkReviewOfBooks
|
||||
from libprs500.ebooks.lrf.web.profiles.spiegelde import SpiegelOnline
|
||||
from libprs500.ebooks.lrf.web.profiles.zeitde import ZeitNachrichten
|
||||
from libprs500.ebooks.lrf.web.profiles.faznet import FazNet
|
||||
from libprs500.ebooks.lrf.web.profiles.wsj import WallStreetJournal
|
||||
from libprs500.ebooks.lrf.web.profiles.barrons import Barrons
|
||||
from libprs500.ebooks.lrf.web.profiles.portfolio import Portfolio
|
||||
|
||||
builtin_profiles = [Barrons, BBC, Economist, FazNet, Newsweek, NewYorkReviewOfBooks, NYTimes, \
|
||||
Portfolio, SpiegelOnline, WallStreetJournal, ZeitNachrichten, \
|
||||
]
|
||||
|
||||
available_profiles = [i.__module__.rpartition('.')[2] for i in builtin_profiles]
|
@ -24,22 +24,8 @@ from libprs500.ebooks.lrf.html.convert_from import process_file
|
||||
from libprs500.web.fetch.simple import create_fetcher
|
||||
|
||||
from libprs500.ebooks.lrf.web.profiles import DefaultProfile
|
||||
from libprs500.ebooks.lrf.web.profiles.nytimes import NYTimes
|
||||
from libprs500.ebooks.lrf.web.profiles.bbc import BBC
|
||||
from libprs500.ebooks.lrf.web.profiles.newsweek import Newsweek
|
||||
from libprs500.ebooks.lrf.web.profiles.economist import Economist
|
||||
from libprs500.ebooks.lrf.web.profiles.newyorkreview import NewYorkReviewOfBooks
|
||||
from libprs500.ebooks.lrf.web.profiles.spiegelde import SpiegelOnline
|
||||
from libprs500.ebooks.lrf.web.profiles.zeitde import ZeitNachrichten
|
||||
from libprs500.ebooks.lrf.web.profiles.faznet import FazNet
|
||||
from libprs500.ebooks.lrf.web.profiles.wsj import WallStreetJournal
|
||||
from libprs500.ebooks.lrf.web.profiles.barrons import Barrons
|
||||
from libprs500.ebooks.lrf.web.profiles.portfolio import Portfolio
|
||||
|
||||
builtin_profiles = [NYTimes, BBC, Newsweek, Economist, NewYorkReviewOfBooks, \
|
||||
SpiegelOnline, ZeitNachrichten, FazNet, WallStreetJournal, \
|
||||
Barrons, Portfolio]
|
||||
available_profiles = [i.__module__.rpartition('.')[2] for i in builtin_profiles]
|
||||
from libprs500.ebooks.lrf.web import builtin_profiles, available_profiles
|
||||
|
||||
|
||||
def option_parser():
|
||||
parser = lrf_option_parser(usage='''%prog [options] website_profile\n\n'''
|
||||
|
@ -38,7 +38,8 @@ class DefaultProfile(object):
|
||||
pubdate_fmt = None # The format string used to parse the publication date in the RSS feed. If set to None some default heuristics are used, these may fail, in which case set this to the correct string or re-implement strptime in your subclass.
|
||||
use_pubdate = True, # If True will look for a publication date for each article. If False assumes the publication date is the current time.
|
||||
no_stylesheets = False # Download stylesheets only if False
|
||||
allow_duplicates = False # If False articles with the same title in the same feed are not downloaded multiple times
|
||||
allow_duplicates = False # If False articles with the same title in the same feed are not downloaded multiple times
|
||||
needs_subscription = False # If True the GUI will ask the userfor a username and password to use while downloading
|
||||
match_regexps = [] # List of regular expressions that determines which links to follow
|
||||
filter_regexps = [] # List of regular expressions that determines which links to ignore
|
||||
# Only one of match_regexps or filter_regexps should be defined
|
||||
@ -51,7 +52,8 @@ class DefaultProfile(object):
|
||||
preprocess_regexps = []
|
||||
|
||||
# See the built-in profiles for examples of these settings.
|
||||
|
||||
|
||||
|
||||
def get_feeds(self):
|
||||
'''
|
||||
Return a list of RSS feeds to fetch for this profile. Each element of the list
|
||||
|
@ -15,6 +15,7 @@ class Barrons(DefaultProfile):
|
||||
title = 'Barron\'s'
|
||||
max_recursions = 3
|
||||
max_articles_per_feed = 50
|
||||
needs_subscription = True
|
||||
timefmt = ' [%a, %b %d, %Y]'
|
||||
html_description = True
|
||||
no_stylesheets = False
|
||||
|
@ -24,6 +24,7 @@ class NYTimes(DefaultProfile):
|
||||
|
||||
title = 'The New York Times'
|
||||
timefmt = ' [%a, %d %b, %Y]'
|
||||
needs_subscription = True
|
||||
max_recursions = 2
|
||||
|
||||
preprocess_regexps = \
|
||||
|
@ -13,7 +13,8 @@ from libprs500.ebooks.lrf.web.profiles import DefaultProfile
|
||||
class WallStreetJournal(DefaultProfile):
|
||||
|
||||
title = 'Wall Street Journal'
|
||||
max_recursions = 2
|
||||
max_recursions = 2
|
||||
needs_subscription = True
|
||||
max_articles_per_feed = 50
|
||||
timefmt = ' [%a, %b %d, %Y]'
|
||||
html_description = True
|
||||
|
@ -39,8 +39,8 @@
|
||||
<file>images/news/newsweek.png</file>
|
||||
<file>images/news/nytimes.png</file>
|
||||
<file>images/news/economist.png</file>
|
||||
<file>images/news/diezeit.png</file>
|
||||
<file>images/news/spiegelonline.png</file>
|
||||
<file>images/news/zeitde.png</file>
|
||||
<file>images/news/spiegelde.png</file>
|
||||
<file>images/news/faznet.png</file>
|
||||
<file>images/next.svg</file>
|
||||
<file>images/page.svg</file>
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 777 B |
Binary file not shown.
Before Width: | Height: | Size: 675 B |
@ -12,80 +12,52 @@
|
||||
## You should have received a copy of the GNU General Public License along
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from PyQt4.QtCore import QObject, SIGNAL
|
||||
from PyQt4.QtGui import QMenu, QIcon, QDialog
|
||||
from PyQt4.QtCore import QObject, SIGNAL, QFile
|
||||
from PyQt4.QtGui import QMenu, QIcon, QDialog, QAction
|
||||
|
||||
from libprs500.gui2.dialogs.password import PasswordDialog
|
||||
from libprs500.ebooks.lrf.web import builtin_profiles, available_profiles
|
||||
|
||||
class NewsAction(QAction):
|
||||
|
||||
def __init__(self, profile, module, parent):
|
||||
self.profile = profile
|
||||
self.module = module
|
||||
if QFile(':/images/news/'+module+'.png').exists():
|
||||
ic = QIcon(':/images/news/'+module+'.png')
|
||||
else:
|
||||
ic = QIcon(':/images/news.svg')
|
||||
QAction.__init__(self, ic, profile.title, parent)
|
||||
QObject.connect(self, SIGNAL('triggered(bool)'), self.fetch_news)
|
||||
QObject.connect(self, SIGNAL('start_news_fetch(PyQt_PyObject, PyQt_PyObject)'),
|
||||
parent.fetch_news)
|
||||
|
||||
def fetch_news(self, checked):
|
||||
self.emit(SIGNAL('start_news_fetch(PyQt_PyObject, PyQt_PyObject)'),
|
||||
self.profile, self.module)
|
||||
|
||||
|
||||
class NewsMenu(QMenu):
|
||||
|
||||
def add_menu_item(self, title, func, icon=':/images/news.svg'):
|
||||
self.addAction(QIcon(icon), title)
|
||||
QObject.connect(self.actions()[-1], SIGNAL('triggered(bool)'), func)
|
||||
|
||||
def __init__(self):
|
||||
QMenu.__init__(self)
|
||||
self.add_menu_item('Barrons', self.fetch_news_barrons)
|
||||
self.add_menu_item('BBC', self.fetch_news_bbc, ':/images/news/bbc.png')
|
||||
self.add_menu_item('Economist', self.fetch_news_economist, ':/images/news/economist.png')
|
||||
self.add_menu_item('Faz.net', self.fetch_news_faznet, ':/images/news/faznet.png')
|
||||
self.add_menu_item('Newsweek', self.fetch_news_newsweek, ':/images/news/newsweek.png')
|
||||
self.add_menu_item('New York Review of Books', self.fetch_news_nyreview, ':/images/book.svg')
|
||||
self.add_menu_item('New York Times', self.fetch_news_nytimes, ':/images/news/nytimes.png')
|
||||
self.add_menu_item('Portfolio.com', self.fetch_news_portfolio)
|
||||
self.add_menu_item('Spiegel Online', self.fetch_news_spiegelde, ':/images/news/spiegelonline.png')
|
||||
self.add_menu_item('Wall Street Journal', self.fetch_news_wsj)
|
||||
self.add_menu_item('Zeit Nachrichten', self.fetch_news_zeitde, ':/images/news/diezeit.png')
|
||||
for profile, module in zip(builtin_profiles, available_profiles):
|
||||
self.addAction(NewsAction(profile, module, self))
|
||||
|
||||
def fetch_news(self, profile, title, username=None, password=None):
|
||||
data = dict(profile=profile, title=title, username=username, password=password)
|
||||
self.emit(SIGNAL('fetch_news(PyQt_PyObject)'), data)
|
||||
|
||||
def fetch_news_portfolio(self, checked):
|
||||
self.fetch_news('portfolio', 'Portfolio.com')
|
||||
|
||||
def fetch_news_spiegelde(self, checked):
|
||||
self.fetch_news('spiegelde', 'Spiegel Online')
|
||||
|
||||
def fetch_news_zeitde(self, checked):
|
||||
self.fetch_news('zeitde', 'Zeit Nachrichten')
|
||||
|
||||
def fetch_news_faznet(self, checked):
|
||||
self.fetch_news('faznet', 'Faz.net')
|
||||
|
||||
def fetch_news_bbc(self, checked):
|
||||
self.fetch_news('bbc', 'BBC')
|
||||
|
||||
def fetch_news_newsweek(self, checked):
|
||||
self.fetch_news('newsweek', 'Newsweek')
|
||||
|
||||
def fetch_news_economist(self, checked):
|
||||
self.fetch_news('economist', 'The Economist')
|
||||
|
||||
def fetch_news_nyreview(self, checked):
|
||||
self.fetch_news('newyorkreview', 'New York Review of Books')
|
||||
|
||||
def fetch_news_nytimes(self, checked):
|
||||
d = PasswordDialog(self, 'nytimes info dialog',
|
||||
'<p>Please enter your username and password for nytimes.com<br>If you do not have an account, you can <a href="http://www.nytimes.com/gst/regi.html">register</a> for free.<br>Without a registration, some articles will not be downloaded correctly. Click OK to proceed.')
|
||||
d.exec_()
|
||||
if d.result() == QDialog.Accepted:
|
||||
un, pw = d.username(), d.password()
|
||||
self.fetch_news('nytimes', 'New York Times', username=un, password=pw)
|
||||
|
||||
def fetch_news_wsj(self, checked):
|
||||
d = PasswordDialog(self, 'wsj info dialog',
|
||||
'<p>Please enter your username and password for wsj.com<br>Click OK to proceed.')
|
||||
d.exec_()
|
||||
if d.result() == QDialog.Accepted:
|
||||
un, pw = d.username(), d.password()
|
||||
self.fetch_news('wsj', 'Wall Street Journal', username=un, password=pw)
|
||||
|
||||
def fetch_news_barrons(self, checked):
|
||||
d = PasswordDialog(self, 'barrons info dialog',
|
||||
'<p>Please enter your username and password for barrons.com<br>Click OK to proceed.')
|
||||
d.exec_()
|
||||
if d.result() == QDialog.Accepted:
|
||||
un, pw = d.username(), d.password()
|
||||
self.fetch_news('barrons', 'Barrons', username=un, password=pw)
|
||||
def fetch_news(self, profile, module):
|
||||
username = password = None
|
||||
fetch = True
|
||||
if profile.needs_subscription:
|
||||
d = PasswordDialog(self, module + ' info dialog',
|
||||
'<p>Please enter your username and password for %s<br>If you do not have one, please subscribe to get access to the articles.<br/> Click OK to proceed.'%(profile.title,))
|
||||
d.exec_()
|
||||
if d.result() == QDialog.Accepted:
|
||||
username, password = d.username(), d.password()
|
||||
else:
|
||||
fetch = False
|
||||
if fetch:
|
||||
data = dict(profile=module, title=profile.title, username=username, password=password)
|
||||
self.emit(SIGNAL('fetch_news(PyQt_PyObject)'), data)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user