Cleaning the code
This commit is contained in:
parent
5c9701bbb0
commit
c7648de3bc
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
.idea/
|
.idea/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
*.db
|
||||||
|
|||||||
18
app.py
18
app.py
@ -4,7 +4,7 @@ from flask_wtf import Form
|
|||||||
from wtforms import StringField
|
from wtforms import StringField
|
||||||
from wtforms.validators import DataRequired
|
from wtforms.validators import DataRequired
|
||||||
from wtforms.widgets import TextArea
|
from wtforms.widgets import TextArea
|
||||||
import parse_incorp
|
import parse_flodata
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
class MyForm(Form):
|
class MyForm(Form):
|
||||||
@ -27,18 +27,16 @@ def textparse():
|
|||||||
errorform = ReportError()
|
errorform = ReportError()
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
g.parsed_data = parse_incorp.parse_flodata(form.flodata.data)
|
parsed_data = parse_flodata.parse_flodata(form.flodata.data)
|
||||||
return render_template('index.html', form=form, parsed_data= g.parsed_data, errorform=errorform)
|
return render_template('index.html', form=form, parsed_data= parsed_data, errorform=errorform)
|
||||||
|
|
||||||
if errorform.validate_on_submit():
|
if errorform.validate_on_submit():
|
||||||
#conn = sqlite3.connect('test.db')
|
conn = sqlite3.connect('test.db')
|
||||||
#sqlquery = 'INSERT INTO errorlogs (flodata, comments) VALUES ({},{})'.format( g.parsed_data['flodata'], errorform.comments.data)
|
sqlquery = 'INSERT INTO errorlogs (flodata, comments) VALUES ({},{})'.format( g.parsed_data['flodata'], errorform.comments.data)
|
||||||
#conn.execute(sqlquery)
|
conn.execute(sqlquery)
|
||||||
print(g.parsed_data)
|
conn.close()
|
||||||
#conn.close()
|
return render_template('index.html', form=form, parsed_data= parsed_data, errorform=errorform)
|
||||||
return render_template('index.html', form=form, parsed_data= g.parsed_data, errorform=errorform)
|
|
||||||
|
|
||||||
return render_template('index.html', form=form, errorform=errorform)
|
return render_template('index.html', form=form, errorform=errorform)
|
||||||
|
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
||||||
|
|||||||
17
flo.py
17
flo.py
@ -1,17 +0,0 @@
|
|||||||
from hashlib import sha256
|
|
||||||
|
|
||||||
digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
|
||||||
|
|
||||||
def decode_base58(bc, length):
|
|
||||||
n = 0
|
|
||||||
for char in bc:
|
|
||||||
n = n * 58 + digits58.index(char)
|
|
||||||
return n.to_bytes(length, 'big')
|
|
||||||
def check_bc(bc):
|
|
||||||
try:
|
|
||||||
bcbytes = decode_base58(bc, 25)
|
|
||||||
return bcbytes[-4:] == sha256(sha256(bcbytes[:-4]).digest()).digest()[:4]
|
|
||||||
except Exception:`
|
|
||||||
return False
|
|
||||||
|
|
||||||
print(check_bc('FN93RGsz25vUPMwoyzQvrM95G5M42PGNWS'))
|
|
||||||
121
parse.py
121
parse.py
@ -1,121 +0,0 @@
|
|||||||
import re
|
|
||||||
import testcases
|
|
||||||
|
|
||||||
marker=None
|
|
||||||
operation=None
|
|
||||||
address=None
|
|
||||||
amount=None
|
|
||||||
|
|
||||||
def extractMarkers(text, markerList):
|
|
||||||
count = 0
|
|
||||||
returnval = None
|
|
||||||
text = text.lower()
|
|
||||||
for marker in markerList:
|
|
||||||
if marker[-1] != '#':
|
|
||||||
marker = marker + '#'
|
|
||||||
marker = marker.lower()
|
|
||||||
|
|
||||||
count = count + text.count(marker)
|
|
||||||
if count > 1:
|
|
||||||
return 'od'
|
|
||||||
if count == 1 and (returnval is None):
|
|
||||||
returnval = marker
|
|
||||||
return returnval
|
|
||||||
|
|
||||||
|
|
||||||
def extractOperation(text, operationList):
|
|
||||||
count = 0
|
|
||||||
returnval = None
|
|
||||||
text = text.lower()
|
|
||||||
for operation in operationList:
|
|
||||||
operation = operation.lower()
|
|
||||||
|
|
||||||
count = count + text.count(operation)
|
|
||||||
if count > 1:
|
|
||||||
return 'od'
|
|
||||||
if count == 1 and (returnval is None):
|
|
||||||
returnval = operation
|
|
||||||
return returnval
|
|
||||||
|
|
||||||
|
|
||||||
def extractAmount(text):
|
|
||||||
count = 0
|
|
||||||
returnval = None
|
|
||||||
text = text.lower()
|
|
||||||
splitText = re.split("\W+", text)
|
|
||||||
|
|
||||||
for word in splitText:
|
|
||||||
word = word.replace('rmt','')
|
|
||||||
try:
|
|
||||||
float(word)
|
|
||||||
count = count + 1
|
|
||||||
returnval = float(word)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if count > 1:
|
|
||||||
return 'od'
|
|
||||||
return returnval
|
|
||||||
|
|
||||||
# Combine test
|
|
||||||
operationList = ['send','transfer','give']
|
|
||||||
markerList = ['ranchimall','rmt']
|
|
||||||
for string in testcases.testStrings:
|
|
||||||
marker = extractOperation(string, markerList)
|
|
||||||
operation = extractOperation(string, operationList)
|
|
||||||
amount = extractAmount(string)
|
|
||||||
|
|
||||||
print('text - ' + string)
|
|
||||||
print('Marker - '+str(marker))
|
|
||||||
print('Operation - '+str(operation))
|
|
||||||
print('Amount - '+str(amount)+'\n\n')
|
|
||||||
|
|
||||||
|
|
||||||
# Marker test
|
|
||||||
'''markerList = ['ranchimall','rmt']
|
|
||||||
for string in testcases.testStrings:
|
|
||||||
returnval = extractMarkers(string, markerList)
|
|
||||||
if returnval is not None:
|
|
||||||
if returnval == 'od':
|
|
||||||
print('text - ' + string)
|
|
||||||
print('Transaction reject\nMore than one marker present\n\n')
|
|
||||||
else:
|
|
||||||
print('text - ' + string)
|
|
||||||
print('Marker - '+str(returnval)+'\n\n')
|
|
||||||
else:
|
|
||||||
print('text - ' + string)
|
|
||||||
print('Marker not found\n\n')
|
|
||||||
|
|
||||||
# Operator test
|
|
||||||
operationList = ['send','transfer','give']
|
|
||||||
for string in testcases.testStrings:
|
|
||||||
returnval = extractOperation(string, operationList)
|
|
||||||
if returnval is not None:
|
|
||||||
if returnval == 'od':
|
|
||||||
print('text - ' + string)
|
|
||||||
print('Transaction reject\nMore than one operation present\n\n')
|
|
||||||
else:
|
|
||||||
print('text - ' + string)
|
|
||||||
print('Operation - '+str(returnval)+'\n\n')
|
|
||||||
else:
|
|
||||||
print('text - ' + string)
|
|
||||||
print('Operation not found\n\n')'''
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
GRAVEYARD
|
|
||||||
----------
|
|
||||||
|
|
||||||
def extractAddress(text):
|
|
||||||
count = 0
|
|
||||||
returnval = None
|
|
||||||
|
|
||||||
for operation in operationList:
|
|
||||||
operation = operation.lower()
|
|
||||||
|
|
||||||
count = count + text.count(operation)
|
|
||||||
if count > 1:
|
|
||||||
return 'od'
|
|
||||||
if count == 1 and (returnval is None):
|
|
||||||
returnval = operation
|
|
||||||
return returnval'''
|
|
||||||
@ -1,35 +1,35 @@
|
|||||||
import re
|
import re
|
||||||
import testcases
|
|
||||||
|
|
||||||
marker=None
|
marker = None
|
||||||
operation=None
|
operation = None
|
||||||
address=None
|
address = None
|
||||||
amount=None
|
amount = None
|
||||||
|
|
||||||
def extractMarkers(text):
|
def isTransfer(text):
|
||||||
returnval = None
|
wordlist = ['transfer','send','give'] #keep everything lowercase
|
||||||
text = text.lower()
|
textList = text.split(' ')
|
||||||
text = ' '.join(text.split())
|
for word in wordlist:
|
||||||
textlst = text.split(' ')
|
if word in textList:
|
||||||
|
return True
|
||||||
for part in textlst:
|
return False
|
||||||
if part[-1] == '#' and len(part)>1:
|
|
||||||
if returnval is not None:
|
|
||||||
return 'od'
|
|
||||||
returnval = part
|
|
||||||
return returnval
|
|
||||||
|
|
||||||
|
|
||||||
def extractOperation(text, operationList):
|
def isIncorp(text):
|
||||||
|
wordlist = ['incorporate','create','start'] # keep everything lowercase
|
||||||
|
textList = text.split(' ')
|
||||||
|
for word in wordlist:
|
||||||
|
if word in textList:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def extractOperation(text):
|
||||||
|
operationList = ['send', 'transfer', 'give'] # keep everything lowercase
|
||||||
count = 0
|
count = 0
|
||||||
returnval = None
|
returnval = None
|
||||||
text = text.lower()
|
|
||||||
for operation in operationList:
|
for operation in operationList:
|
||||||
operation = operation.lower()
|
|
||||||
|
|
||||||
count = count + text.count(operation)
|
count = count + text.count(operation)
|
||||||
if count > 1:
|
if count > 1:
|
||||||
return 'od'
|
return 'Too many'
|
||||||
if count == 1 and (returnval is None):
|
if count == 1 and (returnval is None):
|
||||||
returnval = operation
|
returnval = operation
|
||||||
return returnval
|
return returnval
|
||||||
@ -38,7 +38,6 @@ def extractOperation(text, operationList):
|
|||||||
def extractAmount(text):
|
def extractAmount(text):
|
||||||
count = 0
|
count = 0
|
||||||
returnval = None
|
returnval = None
|
||||||
text = text.lower()
|
|
||||||
splitText = re.split("\W+", text)
|
splitText = re.split("\W+", text)
|
||||||
|
|
||||||
for word in splitText:
|
for word in splitText:
|
||||||
@ -51,21 +50,12 @@ def extractAmount(text):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if count > 1:
|
if count > 1:
|
||||||
return 'od'
|
return 'Too many'
|
||||||
return returnval
|
return returnval
|
||||||
|
|
||||||
def isIncorp(text):
|
|
||||||
wordlist = ['incorporate','create','start']
|
|
||||||
cleantext = re.sub(' +', ' ',text)
|
|
||||||
textList = cleantext.split(' ')
|
|
||||||
for word in wordlist:
|
|
||||||
if word in textList:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def extractIncMarker(text):
|
def extractMarker(text):
|
||||||
cleantext = re.sub(' +', ' ',text)
|
textList = text.split(' ')
|
||||||
textList = cleantext.split(' ')
|
|
||||||
for word in textList:
|
for word in textList:
|
||||||
if word[-1] == '#':
|
if word[-1] == '#':
|
||||||
return word
|
return word
|
||||||
@ -73,8 +63,7 @@ def extractIncMarker(text):
|
|||||||
|
|
||||||
def extractInitTokens(text):
|
def extractInitTokens(text):
|
||||||
base_units = {'thousand':10**3 , 'million':10**6 ,'billion':10**9, 'trillion':10**12}
|
base_units = {'thousand':10**3 , 'million':10**6 ,'billion':10**9, 'trillion':10**12}
|
||||||
cleantext = re.sub(' +', ' ',text)
|
textList = text.split(' ')
|
||||||
textList = cleantext.split(' ')
|
|
||||||
for idx,word in enumerate(textList):
|
for idx,word in enumerate(textList):
|
||||||
try:
|
try:
|
||||||
result = float(word)
|
result = float(word)
|
||||||
@ -84,19 +73,28 @@ def extractInitTokens(text):
|
|||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
# Combine test
|
# Combine test
|
||||||
def parse_flodata(string):
|
def parse_flodata(string):
|
||||||
|
|
||||||
if not isIncorp(string):
|
if string[0:5] == 'text:':
|
||||||
operationList = ['send', 'transfer', 'give']
|
string = string.split('text:')[1]
|
||||||
marker = extractMarkers(string)
|
|
||||||
operation = extractOperation(string, operationList)
|
cleanstring = re.sub(' +', ' ', string)
|
||||||
amount = extractAmount(string)
|
cleanstring = cleanstring.lower()
|
||||||
|
|
||||||
|
if isTransfer(cleanstring):
|
||||||
|
marker = extractMarker(cleanstring)
|
||||||
|
operation = extractOperation(cleanstring)
|
||||||
|
amount = extractAmount(cleanstring)
|
||||||
parsed_data = {'type': 'transfer', 'flodata': string, 'marker': marker, 'operation': operation,
|
parsed_data = {'type': 'transfer', 'flodata': string, 'marker': marker, 'operation': operation,
|
||||||
'amount': amount}
|
'amount': amount}
|
||||||
|
elif isIncorp(cleanstring):
|
||||||
|
incMarker = extractMarker(cleanstring)
|
||||||
|
initTokens = extractAmount(cleanstring)
|
||||||
|
parsed_data = {'type': 'incorporation', 'flodata': string, 'marker': incMarker, 'initTokens': initTokens}
|
||||||
else:
|
else:
|
||||||
incMarker = extractIncMarker(string)
|
parsed_data = {'type': 'noise'}
|
||||||
initTokens = extractInitTokens(string)
|
|
||||||
parsed_data = {'type': 'incorporation', 'flodata': string, 'marker': marker, 'initTokens': initTokens}
|
|
||||||
|
|
||||||
return parsed_data
|
return parsed_data
|
||||||
111
parse_incorp.py
111
parse_incorp.py
@ -1,111 +0,0 @@
|
|||||||
import re
|
|
||||||
import testcases
|
|
||||||
|
|
||||||
marker=None
|
|
||||||
operation=None
|
|
||||||
address=None
|
|
||||||
amount=None
|
|
||||||
|
|
||||||
def extractMarkers(text):
|
|
||||||
returnval = None
|
|
||||||
text = text.lower()
|
|
||||||
textlst = text.split(' ')
|
|
||||||
|
|
||||||
for part in textlst:
|
|
||||||
if part[-1] == '#' and len(part)>1:
|
|
||||||
if returnval is not None:
|
|
||||||
return 'od'
|
|
||||||
returnval = part
|
|
||||||
return returnval
|
|
||||||
|
|
||||||
|
|
||||||
def extractOperation(text, operationList):
|
|
||||||
count = 0
|
|
||||||
returnval = None
|
|
||||||
text = text.lower()
|
|
||||||
for operation in operationList:
|
|
||||||
operation = operation.lower()
|
|
||||||
|
|
||||||
count = count + text.count(operation)
|
|
||||||
if count > 1:
|
|
||||||
return 'od'
|
|
||||||
if count == 1 and (returnval is None):
|
|
||||||
returnval = operation
|
|
||||||
return returnval
|
|
||||||
|
|
||||||
|
|
||||||
def extractAmount(text):
|
|
||||||
count = 0
|
|
||||||
returnval = None
|
|
||||||
text = text.lower()
|
|
||||||
splitText = re.split("\W+", text)
|
|
||||||
|
|
||||||
for word in splitText:
|
|
||||||
word = word.replace('rmt','')
|
|
||||||
try:
|
|
||||||
float(word)
|
|
||||||
count = count + 1
|
|
||||||
returnval = float(word)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if count > 1:
|
|
||||||
return 'od'
|
|
||||||
return returnval
|
|
||||||
|
|
||||||
def isIncorp(text):
|
|
||||||
wordlist = ['incorporate','create','start']
|
|
||||||
cleantext = re.sub(' +', ' ',text)
|
|
||||||
cleantext= cleantext.lower()
|
|
||||||
textList = cleantext.split(' ')
|
|
||||||
for word in wordlist:
|
|
||||||
if word in textList:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def extractIncMarker(text):
|
|
||||||
cleantext = re.sub(' +', ' ',text)
|
|
||||||
textList = cleantext.split(' ')
|
|
||||||
for word in textList:
|
|
||||||
if word[-1] == '#':
|
|
||||||
return word
|
|
||||||
return False
|
|
||||||
|
|
||||||
def extractInitTokens(text):
|
|
||||||
base_units = {'thousand':10**3 , 'million':10**6 ,'billion':10**9, 'trillion':10**12, 'lakh':10**5, 'crore':10**7}
|
|
||||||
cleantext = re.sub(' +', ' ',text)
|
|
||||||
textList = cleantext.split(' ')
|
|
||||||
for idx,word in enumerate(textList):
|
|
||||||
try:
|
|
||||||
result = float(word)
|
|
||||||
if textList[idx+1] in base_units:
|
|
||||||
return result*base_units[textList[idx+1]]
|
|
||||||
return result
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
# Combine test
|
|
||||||
def parse_flodata(string):
|
|
||||||
|
|
||||||
if string[0:5] == 'text:':
|
|
||||||
string = string.split('text:')[1]
|
|
||||||
|
|
||||||
string = string.lower()
|
|
||||||
|
|
||||||
if not isIncorp(string):
|
|
||||||
operationList = ['send', 'transfer', 'give']
|
|
||||||
marker = extractMarkers(string)
|
|
||||||
operation = extractOperation(string, operationList)
|
|
||||||
amount = extractAmount(string)
|
|
||||||
parsed_data = {'type': 'transfer', 'flodata': string, 'marker': marker, 'operation': operation,
|
|
||||||
'amount': amount}
|
|
||||||
else:
|
|
||||||
incMarker = extractIncMarker(string)
|
|
||||||
initTokens = extractInitTokens(string)
|
|
||||||
parsed_data = {'type': 'incorporation', 'flodata': string, 'marker': incMarker, 'initTokens': initTokens}
|
|
||||||
|
|
||||||
return parsed_data
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user