<s> import time <EOL> import threading <EOL> import pprint <EOL> import sys <EOL> import traceback <EOL> import random <EOL> import telepot <EOL> from telepot . namedtuple import InlineQuery , ChosenInlineResult , InlineQueryResultArticle , InlineQueryResultPhoto , InputTextMessageContent <EOL> def equivalent ( data , nt ) : <EOL> if type ( data ) is dict : <EOL> keys = data . keys ( ) <EOL> if len ( keys ) != len ( [ f for f in nt . _fields if getattr ( nt , f ) is not None ] ) : <EOL> return False <EOL> fields = list ( map ( lambda k : k + '<STR_LIT:_>' if k in [ '<STR_LIT>' ] else k , keys ) ) <EOL> return all ( map ( equivalent , [ data [ k ] for k in keys ] , [ getattr ( nt , f ) for f in fields ] ) ) <EOL> elif type ( data ) is list : <EOL> return all ( map ( equivalent , data , nt ) ) <EOL> else : <EOL> return data == nt <EOL> def examine ( result , type ) : <EOL> try : <EOL> print ( '<STR_LIT>' % type ) <EOL> nt = type ( ** result ) <EOL> assert equivalent ( result , nt ) , '<STR_LIT>' % ( result , nt ) <EOL> pprint . pprint ( result ) <EOL> pprint . pprint ( nt ) <EOL> print ( ) <EOL> except AssertionError : <EOL> traceback . print_exc ( ) <EOL> answer = raw_input ( '<STR_LIT>' ) <EOL> if answer != '<STR_LIT:y>' : <EOL> exit ( <NUM_LIT:1> ) <EOL> def on_inline_query ( msg ) : <EOL> def compute ( ) : <EOL> articles = [ InlineQueryResultArticle ( <EOL> id = '<STR_LIT:abc>' , title = '<STR_LIT>' , input_message_content = InputTextMessageContent ( message_text = '<STR_LIT>' ) , url = '<STR_LIT>' , hide_url = True ) , <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , '<STR_LIT:url>' : '<STR_LIT>' } ] <EOL> photos = [ InlineQueryResultPhoto ( <EOL> id = '<STR_LIT>' , photo_url = '<STR_LIT>' , thumb_url = '<STR_LIT>' ) , <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } ] <EOL> results = random . choice ( [ articles , photos ] ) <EOL> return results <EOL> query_id , from_id , query = telepot . glance ( msg , flavor = '<STR_LIT>' ) <EOL> if from_id != USER_ID : <EOL> print ( '<STR_LIT>' , from_id ) <EOL> return <EOL> examine ( msg , InlineQuery ) <EOL> answerer . answer ( msg , compute ) <EOL> def on_chosen_inline_result ( msg ) : <EOL> result_id , from_id , query = telepot . glance ( msg , flavor = '<STR_LIT>' ) <EOL> if from_id != USER_ID : <EOL> print ( '<STR_LIT>' , from_id ) <EOL> return <EOL> examine ( msg , ChosenInlineResult ) <EOL> print ( '<STR_LIT>' ) <EOL> pprint . pprint ( msg ) <EOL> def compute ( inline_query ) : <EOL> articles = [ InlineQueryResultArticle ( <EOL> id = '<STR_LIT:abc>' , title = '<STR_LIT>' , message_text = '<STR_LIT>' , url = '<STR_LIT>' , hide_url = True ) , <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:url>' : '<STR_LIT>' } ] <EOL> photos = [ InlineQueryResultPhoto ( <EOL> id = '<STR_LIT>' , photo_url = '<STR_LIT>' , thumb_url = '<STR_LIT>' ) , <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ] <EOL> results = random . choice ( [ articles , photos ] ) <EOL> return results <EOL> TOKEN = sys . argv [ <NUM_LIT:1> ] <EOL> USER_ID = int ( sys . argv [ <NUM_LIT:2> ] ) <EOL> bot = telepot . Bot ( TOKEN ) <EOL> answerer = telepot . helper . Answerer ( bot ) <EOL> bot . sendMessage ( USER_ID , '<STR_LIT>' ) <EOL> bot . message_loop ( { '<STR_LIT>' : on_inline_query , <EOL> '<STR_LIT>' : on_chosen_inline_result } , run_forever = True ) </s>
