<s> """<STR_LIT>""" <EOL> try : <EOL> from urllib import quote <EOL> except ImportError : <EOL> from urllib . request import quote <EOL> import re <EOL> import requests <EOL> from random import shuffle <EOL> def unescape ( url ) : <EOL> return url . replace ( r"<STR_LIT>" , "<STR_LIT:%>" ) <EOL> def image ( searchterm , unsafe = False ) : <EOL> searchterm = quote ( searchterm ) <EOL> safe = "<STR_LIT>" if unsafe else "<STR_LIT>" <EOL> searchurl = "<STR_LIT>" . format ( searchterm , safe ) <EOL> useragent = "<STR_LIT>" <EOL> result = requests . get ( searchurl , headers = { "<STR_LIT>" : useragent } ) . text <EOL> images = list ( map ( unescape , re . findall ( r"<STR_LIT>" , result ) ) ) <EOL> shuffle ( images ) <EOL> if images : <EOL> return images [ <NUM_LIT:0> ] <EOL> else : <EOL> return "<STR_LIT>" <EOL> def on_message ( msg , server ) : <EOL> text = msg . get ( "<STR_LIT:text>" , "<STR_LIT>" ) <EOL> match = re . findall ( r"<STR_LIT>" , text ) <EOL> if not match : <EOL> return <EOL> searchterm = match [ <NUM_LIT:0> ] <EOL> return image ( searchterm . encode ( "<STR_LIT:utf8>" ) ) </s>
