zoukankan      html  css  js  c++  java
  • feedparser 同步博客园rss到 qq zone

    #!/usr/bin/env python

    #coding=UTF-8

    #FileName: syn_qzone.py

    import smtplib, feedparser, cPickle, sys

    from email.mime.text import MIMEText

    url = "http://www.cnblogs.com/lexus/rss" #feed url(Atom)

    qq_number = "165696916" #qq number

    qq_password = "qw198465" #qq password

    qq_username = qq_number + "@qq.com"

    qzone_add = qq_number + "@qzone.qq.com"

    mailto = [qzone_add]

    try:

        file = open('published_title','r')

        published_title = cPickle.load(file)

    except Exception, e:

        published_title = []

    def mailto_blog(username,password,sub,content,mailto_list):

        msgRoot = MIMEText(content,'html','UTF-8')

        msgRoot['Subject'] = sub

        msgRoot['From'] = username

        msgRoot['To'] = ";".join(mailto_list)

        try:

            s = smtplib.SMTP()

            s.connect("smtp.qq.com")

            try:

                s.login(username, password)

            except Exception,e:

                print "请确认使用了正确的用户名及密码!"

                sys.exit(0)

            s.sendmail(username, mailto_list, msgRoot.as_string())

            s.close()

            return True

        except Exception, e:

            #print str(e)

            return False

    def syn_articles(feed_url):

        feed_data = feedparser.parse(feed_url)

        items = feed_data['items']

        items.reverse()

        for item in items:

            title = item.title.encode('UTF-8')

            link = item.link.encode('UTF-8')

            article = "<b>本文为自动同步,原文地址:<a href=\"" + link + "\">" + link + "</a><br /></b>" + item.description.encode('UTF-8')

            if title in published_title:

                print "失败:\"%s\"已存在,发布失败!" % title

            else:

                if mailto_blog(qq_username,qq_password,title,article,mailto):

                    published_title.append(title)

                    print "成功:\"%s\"已经成功同步!" % title

    syn_articles(url)

    file = open('published_title','w')

    cPickle.dump(published_title, file)

    file.close()

    非我原创我只是改了一下

    reference:

    http://www.feedparser.org/docs/common-rss-elements.html

  • 相关阅读:
    流媒体技术原理及播放方式(浅显易懂)
    实时音视频技术难点及解决方案
    流媒体技术简介
    DSP广告系统架构及关键技术解析(转)
    大型网站架构 图片服务器分离
    大话铁道部12306订票系统云架构
    技术揭秘12306改造(一):尖峰日PV值297亿下可每秒出票1032张
    12306火车票预定系统的需求分析
    PowerDesigner16.5 使用遇到的问题
    Ubuntu不输入密码执行sudo命令方法介绍
  • 原文地址:https://www.cnblogs.com/lexus/p/1808435.html
Copyright © 2011-2022 走看看