<s> import logging <EOL> from flask import Flask , render_template <EOL> from flask_sockets import Sockets <EOL> import requests <EOL> logging . basicConfig ( level = logging . INFO ) <EOL> app = Flask ( __name__ ) <EOL> sockets = Sockets ( app ) <EOL> METADATA_NETWORK_INTERFACE_URL = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def get_external_ip ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> r = requests . get ( <EOL> METADATA_NETWORK_INTERFACE_URL , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } , <EOL> timeout = <NUM_LIT:2> ) <EOL> return r . text <EOL> except requests . RequestException : <EOL> logging . info ( '<STR_LIT>' ) <EOL> return '<STR_LIT:localhost>' <EOL> @ sockets . route ( '<STR_LIT>' ) <EOL> def echo_socket ( ws ) : <EOL> while True : <EOL> message = ws . receive ( ) <EOL> ws . send ( message ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> external_ip = get_external_ip ( ) <EOL> return render_template ( '<STR_LIT>' , external_ip = external_ip ) <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def server_error ( e ) : <EOL> logging . exception ( '<STR_LIT>' ) <EOL> return """<STR_LIT>""" . format ( e ) , <NUM_LIT> <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print ( """<STR_LIT>""" ) </s>
