Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
 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])
Ejemplo n.º 4
0
 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])