<s> from __future__ import unicode_literals <EOL> from irc3 . plugins . command import command <EOL> import irc3 <EOL> __doc__ = '''<STR_LIT>''' <EOL> @ irc3 . plugin <EOL> class Search ( object ) : <EOL> requires = [ <EOL> __name__ . replace ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , bot ) : <EOL> self . bot = bot <EOL> try : <EOL> import requests <EOL> self . session = requests . Session ( ) <EOL> self . session . headers . update ( self . headers ) <EOL> except ImportError : <EOL> self . session = None <EOL> @ command ( permission = '<STR_LIT>' ) <EOL> def ddg ( self , mask , target , args ) : <EOL> """<STR_LIT>""" <EOL> q = '<STR_LIT:U+0020>' . join ( args [ '<STR_LIT>' ] ) <EOL> resp = self . session . get ( '<STR_LIT>' , <EOL> params = dict ( q = q , format = '<STR_LIT>' , t = '<STR_LIT>' ) , <EOL> allow_redirects = False ) <EOL> ctype = resp . headers [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in ctype or '<STR_LIT>' in ctype : <EOL> if resp . status_code == <NUM_LIT:200> : <EOL> data = resp . json ( ) <EOL> return '<STR_LIT>' . format ( ** data ) <EOL> elif resp . status_code == <NUM_LIT> : <EOL> return '<STR_LIT>' . format ( resp . headers [ '<STR_LIT:location>' ] ) </s>
