del.icio.us
コンソールからpostする
enclibというのはPython/やっつけ系日本語処理より。
#!/usr/bin/env python
import sys
import os
import urllib
import urllib2
import urlparse
from enclib import encode
class DelIcioUsURL:
def __init__(self, **kw):
self.url = urlparse.urlunparse((
'https', 'api.del.icio.us', 'v1/posts/add', '',
'&'.join([('%s=%s' % (k, kw[k])) for k in kw]), ''))
def geturl(self):
return self.url
if __name__ == '__main__':
if len(sys.argv) != 3:
print 'Usage: %s url description' % sys.argv[0]
sys.exit(1)
args = [encode(arg, 'utf-8') for arg in sys.argv]
dcu = DelIcioUsURL(
url=args[1],
description=urllib.quote(args[2]))
# execute
# FIXME: analyze XML response, independ from w3m.
os.execvp('w3m', ['w3m', '-dump', dcu.geturl()])