@command(permission='view')
    def ddg(self, mask, target, args):
        """Search using https://duckduckgo.com/api

            %%ddg <query>...
        """
        q = ' '.join(args['<query>'])
        resp = self.session.get('http://api.duckduckgo.com/',
                                params=dict(q=q, format='json', t='irc3'),
                                allow_redirects=False)
        ctype = resp.headers['content-type']
        if 'json' in ctype or 'javascript' in ctype:
            if resp.status_code == 200:
                data = resp.json()
                return '{AbstractText} - {AbstractURL}'.format(**data)
            elif resp.status_code == 303:
                return 'Redirect to: {0}'.format(resp.headers['location'])
dataset/ETHPy150Open gawel/irc3/irc3/plugins/search.py/Search.ddg/original