Ejemplo n.º 1
0
 def send_weibo():
     logging.warning("[%s]准备发送一条微博.." % config.SEND_TIME)
     connect = sqlite3.connect('author_urls.sqlite3')
     cursor = connect.cursor()
     sql = 'select * from urls where used=0'
     cursor.execute(sql)
     data = cursor.fetchone()
     if data:
         author_info = author_detail(base_url, data[1])
         download_avatar(base_url, author_info['avatar'])
         images = [config.AVATAR_FILE]
         content = '简书作者: {name}\n关注: {follow}\n粉丝数: {fans}\n发表文章数: {article_count}\n'\
             '发表文字: {words}\n被喜欢收藏: {lovers}\n简书钻石数: {diamonds}\n'.format(**author_info)
         content += '最新发表:\n'
         for idx, article in enumerate(author_info['articles']):
             content += '- %s\n' % article['title']
             wcpath = os.path.join(config.TEMP_DIR, 'wc%d.jpg' % idx)
             util.create_wordcloud(article['content'], config.WL_FONT_FILE, config.WL_BG_FILE).save(wcpath)
             images.append(wcpath)
         wbmsg = WeiboMessage(content, images=images)
         sw = SinaWeibo(config.USERNAME, config.PASSWORD)
         for idx in range(3):
             if sw.login(captcha_handler):
                 sw.send_weibo(wbmsg)
                 logging.warning("发送微博成功")
                 itchat.send('发送微博成功', toUserName='******')
                 sql = 'update urls set used=1 where id=%s' % data[0]
                 cursor.execute(sql)
                 connect.commit()
                 break
             if idx == 2:
                 logging.warning("发送微博失败")
                 itchat.send('发送微博失败', toUserName='******')
     connect.close()
Ejemplo n.º 2
0
import feedparser
import util

url = 'http://feeds.nos.nl/nosnieuwseconomie'
feed = feedparser.parse(url)

for entry in feed["entries"]:
    util.create_wordcloud(entry.summary, entry.title)