Pixelated Words

[python] Post a list of links to delicious

without comments

Simple script to post a list of links to delicious, along with the related tags for that link.
Yes, I also wish delicious.com supported OAuth

import os, urllib, urllib2, time, sys
from BeautifulSoup import BeautifulSoup
from BeautifulSoup import BeautifulStoneSoup
 
user = 'insert_the_user_name'
pasw = 'insert_the_password'
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, 'https://api.del.icio.us/', user, pasw)
auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
 
for url in open('./all_links.txt'):
    try:
        title = urllib.quote(BeautifulSoup(urllib.urlopen(url)).title.string)
        url = urllib.quote(url)
        tags = "hn_links"
        for suggestion in BeautifulSoup( urllib2.urlopen("https://api.del.icio.us/v1/posts/suggest?url=%s" % url).read()).findAll('popular'):
            tags = tags + "+" + suggestion.string
        print urllib2.urlopen("https://api.del.icio.us/v1/posts/add?url=%s&tags=%s&description=%s" % (url, tags, title)).read()
        time.sleep(9)
    except:
        print sys.exc_info()

Written by Chirag

March 22nd, 2009 at 9:15 pm

Posted in Hacks