add publicserver
This commit is contained in:
parent
8c21ce8fff
commit
cc29b52290
|
@ -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,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()
|
Loading…
Reference in New Issue