在CENTOS上用calibre发送google reader的文章到kindle

       之前用过GAE版本的软件发送google reader的文章到kindle,但是有一些较长的文件不能一次性翻过,得一页页翻,很麻烦;加上不能发送图片,所以较不满意。

      这次用linux服务器上安装CALIBRE解决了以上的问题。不但能发送图片,而且能用五向键一次翻过一些不想细读的文章

       安装过程:(我用的是CENTOS6.2)

一 首先安装calibre:

#python -c "import sys; py3 = sys.version_info[0] > 2; u = __import__('urllib.request' if py3 else 'urllib', fromlist=1); exec(u.urlopen('http://status.calibre-ebook.com/linux_installer').read()); main()"
 

以上方法在calibre官网有介绍

二 其次写一个Calibre的recipe规则,命名为greader.recipe:

#cd  /opt/calibre/bin

#vi greader.recipe

写入以下:

import urllib, re, mechanize
from calibre.web.feeds.recipes import BasicNewsRecipe
from calibre import __appname__
 
class GoogleReader(BasicNewsRecipe):
    title   = 'Google Reader'
    description = 'This recipe fetches from your Google Reader account unread Starred items and unread Feeds you have placed in a folder via the manage subscriptions feature.'
    needs_subscription = True
    __author__ = 'davec, rollercoaster, Starson17'
    base_url = 'http://www.google.com/reader/atom/'
    oldest_article = 365
    max_articles_per_feed = 250
    get_options = '?n=%d&xt=user/-/state/com.google/read' % max_articles_per_feed
    use_embedded_content = True
 
    def get_browser(self):
        br = BasicNewsRecipe.get_browser(self)
        if self.username is not None and self.password is not None:
            request = urllib.urlencode([('Email', self.username), ('Passwd', self.password),
                                        ('service', 'reader'), ('accountType', 'HOSTED_OR_GOOGLE'), ('source', __appname__)])
            response = br.open('https://www.google.com/accounts/ClientLogin', request)
            auth = re.search('Auth=(\S*)', response.read()).group(1)
            cookies = mechanize.CookieJar()
            br = mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))
            br.addheaders = [('Authorization', 'GoogleLogin auth='+auth)]
        self.token = br.open('http://www.google.com/reader/api/0/token').read()
        self.opener = br
        return br
 
    def get_feeds(self):
        feeds = []
        self.tags = []
        soup = self.index_to_soup('http://www.google.com/reader/api/0/tag/list')
        for id in soup.findAll(True, attrs={'name':['id']}):
            url = id.contents[0]
            self.tags.append(url)
            feeds.append((re.search('/([^/]*)$', url).group(1),
                          self.base_url + urllib.quote(url.encode('utf-8')) + self.get_options))
        return feeds
 
    def cleanup(self):
        import time
        self.log.debug("marking as read")
        br = self.opener
        for tag in self.tags:
            t = re.search('/([^/]*)$', tag).group(1)
            req = urllib.urlencode([('T', self.token), ('s', tag),
                                        ('t', t), ('ts', long(time.time()*1000000))])
            response = br.open('http://www.google.com/reader/api/0/mark-all-as-read?client=scroll', req)
            self.log.debug("%s -> %s - %s" % (tag, req, response.read()))

三:写好后,再写一个SHELL脚本执行自动化,命名为pushGR.sh

#vi pushGR.sh

DATE=`date +%F%H%M`
NAME=GoogleReader\($DATE\).mobi
cd /usr/share/calibre/
ebook-convert greader.recipe $NAME --username [email protected] --password xxx --title GR$DATE --output-profile kindle
calibre-smtp -r smtp.gmail.com --username [email protected] --password xxx --port 587 [email protected] [email protected] GoogleReaderRss -s convert -a $NAME
#rm $NAME #是否要删除生成的文件

注意吧[email protected]改为你的邮箱地址;xxx为密码;[email protected]为你的亚马逊邮箱;还有[email protected]已经加入你亚马逊允许转换邮箱列表里面。

四 把文件改为可以执行

#chmod 777 pushGR.sh

五 执行测试

#/opt/calibre/bin/pushGR.sh

一切正常的话几分钟之后kindle就可以收到文件了,如果图片有点多的话文件会较大,kindle 用wifi收到也要蛮久的。

六 在服务器上设定定时执行

#crontab -e

0 7 * * * /opt/calibre/bin/pushGR.sh

每天早上7点发送文章到kindle

 

 

你可能感兴趣的:(centos,Google,reader,kindle,calibre)