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

  • 相关阅读:
    第十章 Ingress
    第九章 Service
    第八章 资源控制器
    第一章 Xshell5评估期已过问题
    第七章 yaml格式
    第六章 资源清单
    第五章 配置私有仓库Harbor
    第四章 K8s部署安装
    36 SpringBoot 在系统配置文件中动态加载配置
    Java 集合、数组 任意个数数字相加等于一个指定的数
  • 原文地址:https://www.cnblogs.com/lexus/p/1808435.html
Copyright © 2011-2022 走看看