The Artima Developer Community
Sponsored Link

Web Buzz Forum
Moving to del.icio.us, part 4

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Stuart Langridge

Posts: 2006
Nickname: aquarius
Registered: Sep, 2003

Stuart Langridge is a web, JavaScript, and Python hacker, and sometimes all three at once.
Moving to del.icio.us, part 4 Posted: Mar 17, 2005 2:56 AM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Stuart Langridge.
Original Post: Moving to del.icio.us, part 4
Feed Title: as days pass by
Feed URL: http://feeds.feedburner.com/kryogenix
Feed Description: scratched tallies on the prison wall
Latest Web Buzz Posts
Latest Web Buzz Posts by Stuart Langridge
Latest Posts From as days pass by

Advertisement

And finally, we need to actually display links from del.icio.us on the front page. Fetch them from del.icio.us hourly and write out a document snippet, and then include that snippet in the page.

First, how to fetch them: a trivial Python script which uses the del.icio.us REST API to get recent posts:
import xmltramp,urllib2,cgi

def e(s):
  return cgi.escape(s).replace('"','"')

authinfo = urllib2.HTTPBasicAuthHandler()
authinfo.add_password('del.icio.us API', 'http://del.icio.us',
  'USERNAME','PASSWORD')
opener = urllib2.build_opener(authinfo)
urllib2.install_opener(opener)
data = urllib2.urlopen('http://del.icio.us/api/posts/recent').read()
dom = xmltramp.parse(data)

out = []
for p in dom['post':]:
  try:
    ext = p('extended')
  except:
    ext = ''
  out.append('<a href="%s" title="%s">%s</a>' % \
  (e(p('href')),e(ext),e(p('description'))))
fp = open('/var/www/kryogenix.org/scripts/index.curlies.cached','w')
fp.write('\n'.join(out))
fp.close()
Then throw a line in crontab to actually run it, with crontab -e:
@hourly python /var/www/kryogenix.org/scripts/get-delicious-recent.py
And finally a brief snippet to include it in the index page, which is a Castalian page:
<?cas
CACHED_COPY = '../scripts/index.curlies.cached'
pfp = open(CACHED_COPY)
response.write(pfp.read())
pfp.close()
?>

and that’s it. Move complete. No more maintaining my own linklog. :)

(Updated: changed the crontab call and the script so that if there’s a failure it doesn’t just blank out index.curlies.cached!)

Read: Moving to del.icio.us, part 4

Topic: Opera Fixes IDN Spoofing Bug Previous Topic   Next Topic Topic: A mantra

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use