Skip to content

Instantly share code, notes, and snippets.

@13k
Created February 8, 2009 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 13k/60193 to your computer and use it in GitHub Desktop.
Save 13k/60193 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Sends a bunch of links to delicious.
#
# This script depends on pydelicious library, which can be found here:
# http://code.google.com/p/pydelicious/
#
# Command-line usage:
#
# delicious_send.py <username> <password> <file with links> [file2, file3, ... ]
#
# Links are read from regular plain text files, one post by line, each line in the format:
# <tags> (space separated) | <Description> | <URL>
#
# The field separators (bars) must be present.
from __future__ import with_statement
import sys
try:
import pydelicious
except ImportError:
print "%s depends on pydelicious, found in http://code.google.com/p/pydelicious" % sys.argv[0]
sys.exit(1)
def usage():
print "Usage: %s <username> <password> <file with links> [file2, file3, ... ]" % sys.argv[0]
if len(sys.argv) < 3:
usage()
sys.exit(1)
username = sys.argv[1]
password = sys.argv[2]
try:
api = pydelicious.DeliciousAPI(username, password)
except pydelicious.PyDeliciousUnauthorizedError:
print "Wrong username or password"
sys.exit(1)
def process(line):
global username, password, api
args = line.split('|')
if len(args) < 3:
return False
(tags, title, url) = map(lambda s: s.strip(), args)
print "Sending bookmark '%s' [%s]" % (title, url)
api.posts_add(url, title, tags=tags, replace=True)
for fname in sys.argv[3:]:
with open(fname) as f:
for n, line in enumerate(f):
line = line.strip()
if not line:
continue
if line.startswith('//'):
continue
try:
process(line)
except Exception, e:
print "Error processing line %d in file %r: %s" % (n, fname, e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment