From cb7ccaf23de8fc577edce77347ba013bd1337ce7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Mar 2009 00:34:02 -0700 Subject: [PATCH] IGN:Automatically email downloaded news --- src/calibre/gui2/device.py | 31 +++++++++++++++++++ src/calibre/gui2/main.py | 1 + .../feeds/recipes/recipe_joelonsoftware.py | 9 +++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 6d6d884807..50b2923d84 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -505,6 +505,37 @@ class DeviceGUI(object): p = p.scaledToHeight(ht, Qt.SmoothTransformation) return (p.width(), p.height(), pixmap_to_data(p)) + def email_news(self, id): + opts = email_config().parse() + accounts = [(account, [x.strip().lower() for x in x[0].split(',')]) + for account, x in opts.accounts.items() if x[1]] + sent_mails = [] + for account, fmts in accounts: + files = self.library_view.model().\ + get_preferred_formats_from_ids([id], fmts) + files = [f.name for f in files if f is not None] + if not files: + continue + attachment = files[0] + mi = self.library_view.model().db.get_metadata(id, + index_is_id=True) + to_s = [account] + subjects = [_('News:')+' '+mi.title] + texts = [_('Attached is the')+' '+mi.title] + attachment_names = [mi.title+os.path.splitext(attachment)[1]] + attachments = [attachment] + jobnames = ['%s:%s'%(id, mi.title)] + remove = [id] if config['delete_news_from_library_on_upload']\ + else [] + self.emailer.send_mails(jobnames, + Dispatcher(partial(self.emails_sent, remove=remove)), + attachments, to_s, subjects, texts, attachment_names) + sent_mails.append(to_s[0]) + if sent_mails: + self.status_bar.showMessage(_('Sent news to')+' '+\ + ', '.join(sent_mails), 3000) + + def sync_news(self): if self.device_connected: ids = list(dynamic.get('news_to_be_synced', set([]))) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 0a4be750a2..54b4306ca4 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -954,6 +954,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): dynamic.set('news_to_be_synced', sync) callback(recipe) self.status_bar.showMessage(recipe.title + _(' fetched.'), 3000) + self.email_news(id) self.sync_news() ############################################################################ diff --git a/src/calibre/web/feeds/recipes/recipe_joelonsoftware.py b/src/calibre/web/feeds/recipes/recipe_joelonsoftware.py index 4f2f018708..b76018d87a 100644 --- a/src/calibre/web/feeds/recipes/recipe_joelonsoftware.py +++ b/src/calibre/web/feeds/recipes/recipe_joelonsoftware.py @@ -8,19 +8,20 @@ joelonsoftware.com from calibre.web.feeds.news import BasicNewsRecipe class Joelonsoftware(BasicNewsRecipe): - + title = 'Joel on Software' __author__ = 'Darko Miletic' description = 'Painless Software Management' language = _('English') no_stylesheets = True use_embedded_content = True - + oldest_article = 60 + cover_url = 'http://www.joelonsoftware.com/RssJoelOnSoftware.jpg' - + html2lrf_options = [ '--comment' , description , '--category' , 'blog,software,news' , '--author' , 'Joel Spolsky' ] - + feeds = [(u'Articles', u'http://www.joelonsoftware.com/rss.xml')]