<s> import json <EOL> import sys <EOL> from pymysqlreplication import BinLogStreamReader <EOL> from pymysqlreplication . row_event import ( <EOL> DeleteRowsEvent , <EOL> UpdateRowsEvent , <EOL> WriteRowsEvent , <EOL> ) <EOL> MYSQL_SETTINGS = { <EOL> "<STR_LIT:host>" : "<STR_LIT:127.0.0.1>" , <EOL> "<STR_LIT:port>" : <NUM_LIT> , <EOL> "<STR_LIT:user>" : "<STR_LIT:root>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> def main ( ) : <EOL> stream = BinLogStreamReader ( <EOL> connection_settings = MYSQL_SETTINGS , <EOL> only_events = [ DeleteRowsEvent , WriteRowsEvent , UpdateRowsEvent ] ) <EOL> for binlogevent in stream : <EOL> for row in binlogevent . rows : <EOL> event = { "<STR_LIT>" : binlogevent . schema , "<STR_LIT>" : binlogevent . table } <EOL> if isinstance ( binlogevent , DeleteRowsEvent ) : <EOL> event [ "<STR_LIT:action>" ] = "<STR_LIT>" <EOL> event = dict ( event . items ( ) + row [ "<STR_LIT>" ] . items ( ) ) <EOL> elif isinstance ( binlogevent , UpdateRowsEvent ) : <EOL> event [ "<STR_LIT:action>" ] = "<STR_LIT>" <EOL> event = dict ( event . items ( ) + row [ "<STR_LIT>" ] . items ( ) ) <EOL> elif isinstance ( binlogevent , WriteRowsEvent ) : <EOL> event [ "<STR_LIT:action>" ] = "<STR_LIT>" <EOL> event = dict ( event . items ( ) + row [ "<STR_LIT>" ] . items ( ) ) <EOL> print json . dumps ( event ) <EOL> sys . stdout . flush ( ) <EOL> stream . close ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
