add publicserver

This commit is contained in:
Roman Storm 2017-12-26 22:22:11 -08:00
parent 8c21ce8fff
commit cc29b52290
5 changed files with 52 additions and 2 deletions

0
errors.json Normal file
View File

0
ethgasAPI.json Normal file
View File

View File

@ -9,7 +9,7 @@ import numpy as np
from web3 import Web3, HTTPProvider
web3 = Web3(HTTPProvider('http://localhost:8545'))
web3 = Web3(HTTPProvider('https://wallet.parity.io'))
### These are the threholds used for % blocks accepting to define the recommended gas prices. can be edited here if desired
@ -83,6 +83,7 @@ def write_to_json(gprecs, prediction_table):
outfile.write(prediction_tableout)
except Exception as e:
print('Error3')
print(e)
def process_block_transactions(block):
@ -234,6 +235,7 @@ def master_control():
return True
except:
print('Error2')
print(traceback.format_exc())
alltx = pd.DataFrame()
@ -247,8 +249,15 @@ def master_control():
block = web3.eth.blockNumber
if (timer.process_block < block):
updated = update_dataframes(timer.process_block)
timer.process_block = timer.process_block + 1
timer.process_block = timer.process_block + 1
errors = 'errors.json'
with open(errors, 'w') as outfile:
json.dump({'health': 'Ok'}, outfile)
except:
print('Error1')
errors = 'errors.json'
with open(errors, 'w') as outfile:
json.dump({'health': 'Notok'}, outfile)
pass
time.sleep(1)

0
predictTable.json Normal file
View File

41
publicserver.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
from http.server import BaseHTTPRequestHandler, HTTPServer
# HTTPRequestHandler class
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
# GET
def do_GET(self):
# Send response status code
self.send_response(200)
# Send headers
self.send_header('Content-type','application/json')
self.end_headers()
# Send message back to client
if(self.path == '/'):
f = open("ethgasAPI.json", "r")
msg = f.read()
self.wfile.write(bytes(msg, "utf8"))
elif(self.path == '/health'):
f = open("errors.json", "r")
msg = f.read()
self.wfile.write(bytes(msg, "utf8"))
else:
self.wfile.write(bytes("{'error': 'API doesnot exist'}", "utf8"))
return
def run():
print('starting server... on http://localhost:8081')
# Server settings
# Choose port 8080, for port 80, which is normally used for a http server, you need root access
server_address = ('127.0.0.1', 8081)
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
print('running server...')
httpd.serve_forever()
run()