<s> import time <EOL> import threading <EOL> import pprint <EOL> import sys <EOL> import traceback <EOL> import telepot <EOL> import telepot . namedtuple <EOL> """<STR_LIT>""" <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> expected_content_type = None <EOL> content_type_iterator = iter ( [ <EOL> '<STR_LIT:text>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:location>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] ) <EOL> def see_every_content_types ( msg ) : <EOL> global expected_content_type , content_type_iterator <EOL> flavor = telepot . flavor ( msg ) <EOL> if flavor == '<STR_LIT>' : <EOL> content_type , chat_type , chat_id = telepot . glance ( msg ) <EOL> from_id = msg [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] <EOL> if chat_id != USER_ID and from_id != USER_ID : <EOL> print '<STR_LIT>' , chat_id , from_id <EOL> return <EOL> examine ( msg , telepot . namedtuple . Message ) <EOL> try : <EOL> if content_type == expected_content_type : <EOL> expected_content_type = content_type_iterator . next ( ) <EOL> bot . sendMessage ( chat_id , '<STR_LIT>' % expected_content_type ) <EOL> else : <EOL> bot . sendMessage ( chat_id , '<STR_LIT>' % ( expected_content_type , expected_content_type ) ) <EOL> except StopIteration : <EOL> bot . sendMessage ( from_id , '<STR_LIT>' ) <EOL> else : <EOL> raise telepot . BadFlavor ( msg ) <EOL> TOKEN = sys . argv [ <NUM_LIT:1> ] <EOL> USER_ID = long ( sys . argv [ <NUM_LIT:2> ] ) <EOL> bot = telepot . Bot ( TOKEN ) <EOL> expected_content_type = content_type_iterator . next ( ) <EOL> bot . sendMessage ( USER_ID , '<STR_LIT>' % expected_content_type ) <EOL> bot . message_loop ( see_every_content_types , run_forever = True ) </s>
