def start_server(root_path): """ Create server instance and forever run it """ try: server = HttpServer(document_root=root_path) server.run_forever() except KeyboardInterrupt: logging.info('Server exited')
def main(api_endpoint, credentials, verbose, input_audio_file, output_audio_path, audio_sample_rate, audio_sample_width, audio_iter_size, audio_block_size, audio_flush_size, grpc_deadline, once, *args, **kwargs): """ """ logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) sonos = sonos_helpers.get_sonos() server = HttpServer(SERVER_PORT) server.start() try: http_request, credentials = auth(credentials) except Exception as e: logging.error('Error loading credentials: %s', e) logging.error('Run google-oauthlib-tool to initialize ' 'new OAuth 2.0 credentials.') return grpc_channel = google.auth.transport.grpc.secure_authorized_channel( credentials, http_request, api_endpoint) logging.info('Connecting to %s', api_endpoint) conversation_stream = configure_conversation_stream( input_audio_file, audio_sample_rate, audio_sample_width, audio_iter_size, audio_block_size, audio_flush_size) with pushtotalk.SampleAssistant(conversation_stream, grpc_channel, grpc_deadline) as assistant: wait_for_user_trigger = not once while True: if wait_for_user_trigger: click.pause(info='Press Enter to send a new request...') continue_conversation = assistant.converse() sonos_out(sonos, SERVER_AUDIO_FILE) wait_for_user_trigger = not continue_conversation if once and (not continue_conversation): break
def main(args): server = HttpServer( port=args.port, address=args.host, webroot=args.webroot, threads=args.threads, connections=args.connections, verbose=args.verbose, ) try: server.run() except KeyboardInterrupt: server.stop()
import argparse import time from server import HttpServer if __name__ == "__main__": parser = argparse.ArgumentParser(description="Starts up the server.") parser.add_argument("host_address", metavar="HOST ADDRESS", help="host address") parser.add_argument( "-p", "--p", metavar="HOST PORT", help="host port", nargs="?", default="8080", dest="host_port", type=int ) parser.add_argument( "-g", "--g", metavar="GPIO PIN", help="GPIO pin", nargs="?", default="4", dest="gpio_pin", type=int ) args = parser.parse_args() host = args.host_address port = args.host_port server = HttpServer((host, port), args.gpio_pin) print time.asctime(), "Server Starts - %s:%s" % (host, port) server.start() server.stop() print time.asctime(), "Server Stops - %s:%s" % (host, port)
import os from spmf import Spmf from pm4py.objects.log.importer.xes import importer import server.HttpServer as server #Starts server with debug server.run_server(True)
from http.server import HTTPServer from dotenv import load_dotenv from server import HttpServer load_dotenv() def get_env(variable_name, default=None): value = os.getenv(variable_name, default) if value is None: raise ValueError( f"{variable_name} is not not presented in environment variables. Check your .env file" ) if str(value).lower() in ("true", "false"): return str(value).lower() == "true" return value if __name__ == "__main__": delta = float(get_env("DELTA", 1.0)) hostName = get_env("HOSTNAME", 'localhost') serverPort = int(get_env("SERVERPORT", 8000)) force_reread_flag = bool(get_env("FORCE_REREAD_FLAG", False)) server = HttpServer(hostName, serverPort, delta, force_reread_flag) server.run()
HOST = '127.0.0.1' PORT = 80 LISTNERS = 100 MSGSIZE = 1024 def parse_arguments(): parser = argparse.ArgumentParser() parser.add_argument('-r', '--root', default=os.environ.get('DOCUMENT_ROOT'), help='Root directory for reading files') parser.add_argument('-c', '--ncpu', default=3, type=int, help='Number of cpu') return parser.parse_args() if __name__ == "__main__": args = parse_arguments() if not os.path.exists(args.root): print("Please, check root directory.") sys.exit() server = HttpServer() server.start(args.root, Handler, HOST, PORT, args.ncpu, LISTNERS, MSGSIZE)
#Run server from server import HttpServer server = HttpServer() server.run()
#!/usr/bin/python from config.ServerConfig import ServerConfig as conf from server import HttpServer as server from BaseHTTPServer import HTTPServer PORT_NUMBER=conf.PORT_NUMBER if __name__ == '__main__' : try: #Create a web server and define the handler to manage the incoming request server = HTTPServer(('', PORT_NUMBER), server.httpHandler) print 'Started listening on port ' , PORT_NUMBER #Wait forever for incoming htto requests server.serve_forever() except KeyboardInterrupt: print 'KeyboardInterrupt received, shutting down the web server' server.socket.close() except Exception,e: print "an exception occurred" , e
from server import HttpServer from httpapp import AppServer server = HttpServer('127.0.0.1', 8001, '127.0.0.1', 8500, AppServer) server.startServer()
def kline_callback(self, msg): if msg['k']['x']: df = pd.DataFrame() df['date'] = [msg['k']['T']] df['open'] = np.array([msg['k']['o']]).astype(np.float) df['high'] = np.array([msg['k']['h']]).astype(np.float) df['low'] = np.array([msg['k']['l']]).astype(np.float) df['close'] = np.array([msg['k']['c']]).astype(np.float) df['volume'] = np.array([msg['k']['v']]).astype(np.float) self.data = self.data.append(df, ignore_index=True) self.calculate_ta() self.define_trend() self.on_update() def start_websocket(self): self.websocket.start_kline_socket(self.symbol, self.kline_callback, self.interval) if __name__ == '__main__': global_logger = Logger() http_server = HttpServer(global_logger) threading.Thread(target=http_server.start, args=()).start() bot = BinanceBot(os.getenv("BINANCE_KEY"), os.getenv("BINANCE_SECRET"), "ETHUSDT", KLINE_INTERVAL_15MINUTE, global_logger) bot.start()