<s> import requests <EOL> import collections <EOL> import sys <EOL> import time <EOL> import json <EOL> Entry = collections . namedtuple ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ROW_TYPES = { } <EOL> def row_type_for_columns ( name , column_names ) : <EOL> column_names = tuple ( column_names ) <EOL> row_type = ROW_TYPES . get ( ( name , column_names ) ) <EOL> if row_type is None : <EOL> row_type = collections . namedtuple ( name , column_names ) <EOL> ROW_TYPES [ ( name , column_names ) ] = row_type <EOL> return row_type <EOL> def parse_response ( content ) : <EOL> streams = json . loads ( content ) <EOL> result = { } <EOL> for name , value in streams . items ( ) : <EOL> row_type = row_type_for_columns ( name , value [ "<STR_LIT>" ] ) <EOL> position = value [ "<STR_LIT>" ] <EOL> rows = [ row_type ( * row ) for row in value [ "<STR_LIT>" ] ] <EOL> result [ name ] = Entry ( name , position , rows ) <EOL> return result <EOL> def replicate ( server , streams ) : <EOL> return parse_response ( requests . get ( <EOL> server + "<STR_LIT>" , <EOL> verify = False , <EOL> params = streams <EOL> ) . content ) <EOL> def main ( ) : <EOL> server = sys . argv [ <NUM_LIT:1> ] <EOL> streams = None <EOL> while not streams : <EOL> try : <EOL> streams = { <EOL> row . name : row . position <EOL> for row in replicate ( server , { "<STR_LIT>" : "<STR_LIT>" } ) [ "<STR_LIT>" ] . rows <EOL> } <EOL> except requests . exceptions . ConnectionError as e : <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> while True : <EOL> try : <EOL> results = replicate ( server , streams ) <EOL> except : <EOL> sys . stdout . write ( "<STR_LIT>" + repr ( streams ) + "<STR_LIT>" ) <EOL> break <EOL> for update in results . values ( ) : <EOL> for row in update . rows : <EOL> sys . stdout . write ( repr ( row ) + "<STR_LIT:\n>" ) <EOL> streams [ update . name ] = update . position <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
