日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

真正的Web2.0:書簽?標(biāo)記?_Web服務(wù)技巧_Web2.0_TechTarget IT...

 weicat 2007-08-03
本土方法

  您可能只是對門面仰慕已久,而在 Web 2.0 站點(diǎn)的某些點(diǎn)上,您會(huì)尋求某些工具,用甚至站點(diǎn)創(chuàng)建者都沒有預(yù)見到的方法獲得站點(diǎn)功能。對于 del. 來說,有很多這樣的工具。開始時(shí),站點(diǎn)的創(chuàng)建者提供他們自己的一些工具,從可用于在其他站點(diǎn)上顯示您網(wǎng)絡(luò)中的帖子的標(biāo)記到瀏覽器工具欄。此外,一百多個(gè)第三方工具覆蓋了您能想像到的 del. 的大多數(shù)用途,大多數(shù),但并非全部,所以可以這樣歸納,Web 2.0 站點(diǎn)的重要性就在于您可以突破編譯器或解釋程序,創(chuàng)建您自己的特性。

  Web 提要:便宜的 API

  del. 的官方 API 使用 HTTP 以及 SSL 和身份驗(yàn)證。但是如果您只需要讀訪問,那么可以選擇整體上采用 Web 2.0 的更為官方的 API:Web 提要。您可以訪問用戶(http://del./rss/<username>)、標(biāo)記(http://del./rss/<tag>)或者兩者組合(http://del./rss/<username>/<tag>)的 Web 提要。那么問題只在于解析 Web 提要以提取所需信息。清單 1 提供了一個(gè)示例。它是 Python 代碼,該代碼發(fā)送包含前一天 del. 提要條目的電子郵件。

  清單 1. 用于發(fā)送前一天 del. 帖子的電子郵件的代碼

import time
import smtplib
from email.MIMEText import MIMEText
from datetime import date, timedelta

import amara

#The base URI for all tags
TAGBASE = ‘http://del./tag/‘

#Set FEEDS to customize which feeds you want to monitor
FEEDS = [‘http://del./rss/uche‘, ‘http://del./rss/popular‘]

FROM = ‘del.@example.com‘
TO = ‘user@example.com‘
SMTPHOST = ‘localhost‘

#Compute the date string for yesterday in ISO-8601 format
yesterday = (date(*time.gmtime()[:3]) - timedelta(1)).isoformat()

message_text = u‘‘

#Using Amara. Easy to just grab the RSS feed
for feed in FEEDS:
    doc = amara.parse(feed)
    message_text += u‘\n‘ + unicode(doc.RDF.channel.title) + u‘\n\n‘
    current_items = [ item for item in doc.RDF.item
                      if unicode(item.date).startswith(yesterday) ]
    for item in current_items:
        #Get the properties of the link, defaulting to empty string
        title = unicode(getattr(item, ‘title‘, u‘‘))
        href = unicode(getattr(item, ‘link‘, u‘‘))
        desc = unicode(getattr(item, ‘description‘, u‘‘))
        creator = unicode(getattr(item, ‘creator‘, u‘‘))
        message_text += u‘<%s>--"%s" (from %s)\n‘%(href, title, creator)
        message_text += desc + ‘\n‘

#Be sure to handle Unicode by encoding to UTF-8
msg = MIMEText(message_text.encode(‘utf-8‘))

#Set message metadata
msg[‘Subject‘] = u‘del. bookmarks for %s\n‘ % yesterday
msg[‘From‘] = FROM
msg[‘To‘] = TO

#Send the message via the specified SMTP server
s = smtplib.SMTP()
s.connect(SMTPHOST)
#s.login(SMTP_USERNAME, SMTP_PASSWORD) #If login is necessary
s.sendmail(FROM, [TO], msg.as_string())
s.close()

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多