def main(): # We have settings? if os.path.exists('settings.py'): parse_config_file('settings.py') # What about command line args? parse_command_line() ssl_options = {} # Check SSL options if (options.certfile and options.keyfile) and (os.path.exists( os.path.abspath(options.certfile)) and os.path.exists( os.path.abspath(options.keyfile))): ssl_options['certfile'] = os.path.abspath(options.certfile) ssl_options['keyfile'] = os.path.abspath(options.keyfile) server = HTTPServer(app(), ssl_options=ssl_options or None) if options.debug: options.address = '127.0.0.1' log.debug('Run application in debug mode on %s:%s.' % (options.address, options.port)) server.listen(options.port, options.address) else: log.debug('Run application in normal mode on %s:%s.' % (options.address, options.port)) server.bind(options.port, options.address) server.start(0) IOLoop.instance().start()
def test(): #fetch all the zipcodes for project query = "SELECT Zip FROM dddm.test_zips" zip_df = pd.read_sql(query, md.connect()) zip_list = zip_df['Zip'].tolist() #build a dataframe and push to table df = pd.DataFrame(columns=['zip','seaport','landprice','oilreserve', 'existingplants','disasters','railroad', 'populationdensity', 'elevation', 'water', 'weather', 'rules','earthquake','prediction']) for zipcode in zip_list: result = app.app(zipcode, 50) listData = pd.DataFrame([[zipcode, result.prediction_df['seaport'], result.prediction_df['landprice'], result.prediction_df['oilreserve'], result.prediction_df['existingplants'], result.prediction_df['disasters'], result.prediction_df['railroad'], result.prediction_df['populationdensity'], result.elevation_data, result.water_data, result.weather_data, result.rules, result.earthquake_data, result.prediction]], columns=['zip','seaport','landprice','oilreserve', 'existingplants','disasters','railroad', 'populationdensity', 'elevation', 'water', 'weather', 'rules','earthquake','prediction']) df = df.append(listData, ignore_index=True) df.to_sql(name='test_data', con=md.connect(), if_exists='append', index=False)
def test_success(self, element_count_mock, fizz_or_buzz_mock, app_output_mock): ''' app() shall call the appropriate functions and pass the correct arguments ''' element_count_mock.return_value = sentinel.count fizz_or_buzz_mock.return_value = sentinel.divisors app(sentinel.url, sentinel.tag) element_count_mock.assert_called_once_with(sentinel.url, sentinel.tag) fizz_or_buzz_mock.assert_called_once_with(sentinel.count) app_output_mock.assert_called_once_with( sentinel.url, sentinel.tag, sentinel.count, sentinel.divisors)
def request_handler(self, new_client_socket): recv_data = new_client_socket.recv(1024) if not recv_data: print("客户端断开连接") new_client_socket.close() return recv_text = recv_data.decode() ret_list = recv_text.split('\r\n') ret = re.search("\s(.*)\s", ret_list[0]) if ret == '': print("请求路径不正确") new_client_socket.close() return request_path = ret.group(1) print('请求路径:', request_path) if request_path == "/": request_path = "/index.html" # 判端动态资源请求 if request_path.endswith(".html"): evn = {"path_info": request_path} # 框架包 status, heads, response_body = application.app(evn) response_line = "HTTP/1.1 %s\r\n" % status response_head = '' for head in heads: response_head = "%s:%s\r\n" % head response_data = (response_line + response_head + "\r\n" + response_body).encode() new_client_socket.send(response_data) new_client_socket.close() # 静态资源请求 else: # 拼接响应报文 response_head = "Server:pythonBWs/1.1\r\n" response_blank = "\r\n" response_body = '' response_line = '' try: with open("static" + request_path, 'rb') as file: response_body = file.read() except Exception as e: response_line = "HTTP/1.1 404 NOT Found\r\n" response_body = "Error:%s\r\n" % e else: response_line = "HTTP/1.1 200 OK\r\n" finally: response_data = (response_line + response_head + response_blank).encode() + response_body new_client_socket.send(response_data) new_client_socket.close()
def do_process(self, request): env = request.headers env['method'] = request.command env['path'] = self.get_path() if env['method'] == 'POST': env['body'] = self.get_post_content() resp_status = [] def start_response(status, headers): resp_status.append(int(status[0:3])) print "START RESPONSE" for k in headers: self.set_response_header(k[0], k[1]) resp = app(env, start_response) txt = '' for r in resp: txt += str(r) return resp_status[0], txt
from dotenv import load_dotenv load_dotenv() from application import app app()
def callback(): result = model.app(e.get(), e1.get()) if (result.prediction == "Y"): pred_string = "Approval Status: APPROVED" else: pred_string = "Approval Status: NOT APPROVED" if (result.water_data is not None): water_string = "Water sources around the given zipcode: " + str( result.water_data.shape[0]) else: water_string = " " if (result.earthquake_data is not None): earthquake_string = "Reported earthquakes in the region: " + str( result.earthquake_data.shape[0]) else: earthquake_string = " " if (result.rules is not None and len(result.rules) > 0): broken_string = [ result.rules[i:i + 80] for i in range(0, len(result.rules), 80) ] rules_string = "Subject to following rules: \n" for x in range(0, len(broken_string)): rules_string += broken_string[x] + "\n" else: rules_string = " " if ((result.weather_data is not None) and (result.weather_data.empty == False)): weather_string = str(result.weather_data) else: weather_string = " " values = [ result.prediction_df[0][0], result.prediction_df[0][1], result.prediction_df[0][2], result.prediction_df[0][3], result.prediction_df[0][4], result.prediction_df[0][5], result.prediction_df[0][6], result.prediction_df[0][7] ] value_strings = ["", "", "", "", "", "", "", ""] i = 0 while i < len(values): if (values[i] == 3): value_strings[i] = "Great" elif (values[i] == 2): value_strings[i] = "Average" elif (values[i] == 1): value_strings[i] = "Poor" elif (values[i] == -1): value_strings[i] = "No Data" i = i + 1 l2["text"] = "\n" + pred_string + "\n\n" + earthquake_string + "\n" + water_string prediction_string = "Seaport: " + value_strings[ 0] + "\n Land Price: " + value_strings[ 1] + "\n Oil Reserve: " + value_strings[ 2] + "\n Existing Plants: " + value_strings[ 3] + "\n Disasters: " + value_strings[ 4] + "\n Railroad: " + value_strings[ 5] + "\n Population Density: " + value_strings[ 6] + "\n Elevation: " + value_strings[7] l3["text"] = rules_string + "\n" + weather_string + "\n" + prediction_string
import application as ap ap.app()
def setup(self): self._application = application.app(self) self._application.listen(self.getConfig('interface_http_port')) self.ioloop = tornado.ioloop.IOLoop.instance() self.log('Setup complete')
import tornado.web from application import app if __name__ == "__main__": print("Building app...") app = app() print("Listening...") app.listen(8080) print("Starting loop...") tornado.ioloop.IOLoop.current().start()
def process(): root.destroy() ap.app() # check and re-do the car purchase plan generate procedure