scripts /

#!/usr/bin/env python2
Delicious CLI

A simple script to easily create bookmarks in Delicious via command line.

It is recommended to put a wrapper like this to ``~/bin/b``::

    python2 ~/src/scripts/ add my-user-name $@

The usage will be as follows::

    $ b -t search,bigbrother
    Added "Google" with tags "search,bigbrother".

Note that you don't have to specify the title. However, if you need to do it
(e.g. in case if the script fails to determine it), you can use the ``--title``
from argh import arg, dispatch_command
import requests
from BeautifulSoup import BeautifulSoup
from pydelicious import DeliciousAPI
from getpass import getpass

@arg('-t', '--tags')
@arg('-d', '--description')
@arg('--private', default=False)
def add_bookmark(args):
    url = args.url
    if not url.startswith('http://'):
        url = 'http://' + url

    if args.title:
        title = args.title
        resp = requests.get(url)
        soup = BeautifulSoup(resp.content)
        title = soup.find('title').text.strip()

    tags = args.tags or 'unsorted'

    api = DeliciousAPI(args.username, getpass('Password:'))
    api.posts_add(url, title, tags=tags, extended=args.description,
                  shared=not args.private)

    print u'Added "{0}" with tags "{1}".'.format(title, tags)