<s> import sys <EOL> import urllib2 <EOL> from redash . query_runner import * <EOL> class Url ( BaseQueryRunner ) : <EOL> @ classmethod <EOL> def configuration_schema ( cls ) : <EOL> return { <EOL> '<STR_LIT:type>' : '<STR_LIT:object>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:url>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> @ classmethod <EOL> def annotate_query ( cls ) : <EOL> return False <EOL> def run_query ( self , query ) : <EOL> base_url = self . configuration . get ( "<STR_LIT:url>" , None ) <EOL> try : <EOL> error = None <EOL> query = query . strip ( ) <EOL> if base_url is not None and base_url != "<STR_LIT>" : <EOL> if query . find ( "<STR_LIT>" ) > - <NUM_LIT:1> : <EOL> return None , "<STR_LIT>" % base_url <EOL> if base_url is None : <EOL> base_url = "<STR_LIT>" <EOL> url = base_url + query <EOL> json_data = urllib2 . urlopen ( url ) . read ( ) . strip ( ) <EOL> if not json_data : <EOL> error = "<STR_LIT>" % url <EOL> return json_data , error <EOL> except urllib2 . URLError as e : <EOL> return None , str ( e ) <EOL> except KeyboardInterrupt : <EOL> error = "<STR_LIT>" <EOL> json_data = None <EOL> except Exception as e : <EOL> raise sys . exc_info ( ) [ <NUM_LIT:1> ] , None , sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> return json_data , error <EOL> register ( Url ) </s>
