-
Notifications
You must be signed in to change notification settings - Fork 7
/
selfupdate.py
27 lines (21 loc) · 903 Bytes
/
selfupdate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from web3 import Web3
from userconfig import NODE_ADDRESS
import fileinput
web3 = Web3(Web3.HTTPProvider(NODE_ADDRESS))
def updater(known_states, NUM_OF_STATES):
if known_states > NUM_OF_STATES:
print('The current known state is higher than config...Updating Config...')
print('Known States = ', known_states)
print('Config File States = ', NUM_OF_STATES)
##TODO: CHECK KNOWN STATES HAVE INCREASED BEFORE MAKING ANOTHER WRITE
replace_in_file('knownstates.py', str(NUM_OF_STATES), str(known_states))
print('New state config is now', known_states)
if known_states < NUM_OF_STATES:
print('NOT IN SYNC WITH NETWORK YET, COME BACK SOON')
def replace_in_file(file_path, search_text, new_text):
with fileinput.input(file_path, inplace=True) as f:
for line in f:
new_line = line.replace(search_text, new_text)
print(new_line, end='')