class Delicious(object): """Simple API frontend""" baseurl = u'https://api.del.icio.us/' posturl = urljoin(baseurl, u'/v1/posts/add') title = re.compile(r'<title>(.*?)</title>', re.I+re.DOTALL) def __init__(self, username, password): password_mgr = HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, self.posturl, username, password) auth_handler = HTTPBasicAuthHandler(password_mgr) self.ua = UserAgent(handlers=[auth_handler]) def post(self, url, tags): try: html = self.ua.open(url, size=2048) title = stripHTML(self.title.search(html).group(1)) except AttributeError: title = url opts = {u'url': url, u'description': title, u'tags': u' '.join(tags), u'replace': u'no', u'shared': u'yes'} self.ua.open(self.posturl, opts=opts)
class Delicious(Base): """Simple API frontend""" baseurl = 'https://api.del.icio.us/' posturl = urljoin(baseurl, '/v1/posts/add') title = re.compile(r'<title>(.*?)</title>', re.I + re.DOTALL) def __init__(self, username, password): password_mgr = HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, self.posturl, username, password) auth_handler = HTTPBasicAuthHandler(password_mgr) self.ua = UserAgent(handlers=[auth_handler]) def post(self, url, tags): try: html = self.ua.openurl(url, size=2048) title = stripHTML(self.title.search(html).group(1)) except: title = url opts = { 'url': url, 'description': title, 'tags': ' '.join(tags), 'replace': 'no', 'shared': 'yes', } self.ua.openurl(self.posturl, opts=opts)
def __init__(self, username, password): password_mgr = HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, self.posturl, username, password) auth_handler = HTTPBasicAuthHandler(password_mgr) self.ua = UserAgent(handlers=[auth_handler])