Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions gasExpress.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import time
import sys
import json
Expand All @@ -9,7 +10,7 @@
from web3 import Web3, HTTPProvider


web3 = Web3(HTTPProvider('http://localhost:8545'))
web3 = Web3(HTTPProvider('https://kovan.ethichub.com'))

### These are the threholds used for % blocks accepting to define the recommended gas prices. can be edited here if desired

Expand Down Expand Up @@ -68,18 +69,18 @@ def to_dataframe(self):
data = {0:{'block_number':self.block_number, 'blockhash':self.blockhash, 'time_mined':self.time_mined, 'mingasprice':self.mingasprice}}
return pd.DataFrame.from_dict(data, orient='index')

def write_to_json(gprecs, prediction_table):
def write_to_json(gprecs, prediction_table, path):
"""write json data"""
try:
prediction_table['gasprice'] = prediction_table['gasprice']/10
prediction_tableout = prediction_table.to_json(orient='records')
filepath_gprecs = 'ethgasAPI.json'
filepath_prediction_table = 'predictTable.json'

with open(filepath_gprecs, 'w') as outfile:
with open(path + filepath_gprecs, 'w') as outfile:
json.dump(gprecs, outfile)

with open(filepath_prediction_table, 'w') as outfile:
with open(path + filepath_prediction_table, 'w') as outfile:
outfile.write(prediction_tableout)

except Exception as e:
Expand Down Expand Up @@ -175,7 +176,7 @@ def get_fastest():
gprecs['blockNum'] = block
return(gprecs)

def master_control():
def master_control(path: str):

def init (block):
nonlocal alltx
Expand Down Expand Up @@ -230,7 +231,7 @@ def update_dataframes(block):
print(gprecs)

#every block, write gprecs, predictions
write_to_json(gprecs, predictiondf)
write_to_json(gprecs, predictiondf, path)
return True

except:
Expand All @@ -253,4 +254,10 @@ def update_dataframes(block):

time.sleep(1)

master_control()

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Create json to EtherGasStation Oracle')
parser.add_argument('--path', '-p', metavar='path', required=False, default='',
help='the path to create json files')
args = parser.parse_args()
master_control(path=args.path)
28 changes: 3 additions & 25 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
certifi==2017.11.5
chardet==3.0.4
cytoolz==0.8.2
eth-abi==0.5.0
eth-keyfile==0.4.0
eth-keys==0.1.0b3
eth-tester==0.1.0b5
eth-utils==0.7.1
idna==2.6
numpy==1.13.3
pandas==0.21.0
pycryptodome==3.4.7
pylru==1.0.9
pysha3==1.0.2
python-dateutil==2.6.1
pytz==2017.3
requests==2.18.4
rlp==0.6.0
scipy==1.0.0
semantic-version==2.6.0
six==1.11.0
toolz==0.8.2
typing==3.6.2
urllib3==1.24.2
web3==3.16.4
pandas==1.0.5
numpy==1.19.0
web3==5.11.1