1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 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.icio.us/tag/' #Set FEEDS to customize which feeds you want to monitor FEEDS = ['http://del.icio.us/rss/uche', 'http://del.icio.us/rss/popular'] FROM = 'del.icio.us@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.icio.us 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() |
请在两次查询之间至少等待一秒钟,否则可能会自动控制您的速度。如果您发布一个库以访问 API,则必须做到这一点。该页面还包含其他警告,并且大多数警告适用于任何免费的、开放的 Web API,因此,花时间去关注那些能使您成为优秀 Web 开发者公民的惯例是值得的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <title>Bookmarks from del.icio.us</title> <script type="text/javascript" src="//del.icio.us/feeds/json/uche?count=10"> //Loads JSON from del.icio.us, which evaluates to an an array: Delicious.posts </script> <script type="text/javascript"> //Set up asynchronous display of images function showImage(img){ return (function(){ img.style.display='inline'; }) }; function showBookmarks() { var ul = document.createElement('ul'); //Process each item in the del.icio.us JSON feed for (var i=0, post; post = Delicious.posts; i++) { var li = document.createElement('li'); var a = document.createElement('a'); var img = document.createElement('img'); a.style.marginLeft = '20px'; img.style.position = 'absolute'; //Don't display image at first: will be asynchronously turned on img.style.display = 'none'; img.height = img.width = 16; //Raw string processing to get the URL of the bookmark icon img.src = post.u.split('/').splice(0,3).join('/')+'/favicon.ico'; img.onload = showImage(img); a.setAttribute('href', post.u); a.appendChild(document.createTextNode(post.d)); li.appendChild(img); li.appendChild(a); ul.appendChild(li); } //No bullet markings for list items ul.style.setProperty('list-style', 'none', 'important'); //Replace a targeted portion of initial content with the constructed list var removeTarget = document.getElementById('removeTarget'); var updateTarget = document.getElementById('updateTarget'); updateTarget.removeChild(removeTarget); updateTarget.appendChild(ul); } </script> </head> <body id='updateTarget'> <h2>Bookmarks from del.icio.us</h2> <p id='removeTarget'> <a href="javascript:showBookmarks()">Click here to load addresses</a> </p> </body> </html> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |