您可能只是對門面仰慕已久,而在 Web 2.0 站點的某些點上,您會尋求某些工具,用甚至站點創(chuàng)建者都沒有預(yù)見到的方法獲得站點功能。對于 del.icio.us 來說,有很多這樣的工具。開始時,站點的創(chuàng)建者提供他們自己的一些工具,從可用于在其他站點上顯示您網(wǎng)絡(luò)中的帖子的標記到瀏覽器工具欄。此外,一百多個第三方工具覆蓋了您能想像到的 del.icio.us 的大多數(shù)用途,大多數(shù),但并非全部,所以可以這樣歸納,Web 2.0 站點的重要性就在于您可以突破編譯器或解釋程序,創(chuàng)建您自己的特性。
Web 提要:便宜的 API
del.icio.us 的官方 API 使用 HTTP 以及 SSL 和身份驗證。但是如果您只需要讀訪問,那么可以選擇整體上采用 Web 2.0 的更為官方的 API:Web 提要。您可以訪問用戶(http://del.icio.us/rss/<username> 清單 1. 用于發(fā)送前一天 del.icio.us 帖子的電子郵件的代碼 import time import amara #The base URI for all tags #Set FEEDS to customize which feeds you want to monitor FROM = ‘del.icio.us@example.com‘ #Compute the date string for yesterday in ISO-8601 format message_text = u‘‘ #Using Amara. Easy to just grab the RSS feed #Be sure to handle Unicode by encoding to UTF-8 #Set message metadata #Send the message via the specified SMTP server
import smtplib
from email.MIMEText import MIMEText
from datetime import date, timedelta
TAGBASE = ‘http://del.icio.us/tag/‘
FEEDS = [‘http://del.icio.us/rss/uche‘, ‘http://del.icio.us/rss/popular‘]
TO = ‘user@example.com‘
SMTPHOST = ‘localhost‘
yesterday = (date(*time.gmtime()[:3]) - timedelta(1)).isoformat()
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‘
msg = MIMEText(message_text.encode(‘utf-8‘))
msg[‘Subject‘] = u‘del.icio.us bookmarks for %s\n‘ % yesterday
msg[‘From‘] = FROM
msg[‘To‘] = TO
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()