diff --git a/.gitignore b/.gitignore index 2483976..c713bfc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ __pycache__/ +*.db diff --git a/app.py b/app.py index 9023dd3..10b771f 100644 --- a/app.py +++ b/app.py @@ -4,7 +4,7 @@ from flask_wtf import Form from wtforms import StringField from wtforms.validators import DataRequired from wtforms.widgets import TextArea -import parse_incorp +import parse_flodata import sqlite3 class MyForm(Form): @@ -27,18 +27,16 @@ def textparse(): errorform = ReportError() if form.validate_on_submit(): - g.parsed_data = parse_incorp.parse_flodata(form.flodata.data) - return render_template('index.html', form=form, parsed_data= g.parsed_data, errorform=errorform) + parsed_data = parse_flodata.parse_flodata(form.flodata.data) + return render_template('index.html', form=form, parsed_data= parsed_data, errorform=errorform) if errorform.validate_on_submit(): - #conn = sqlite3.connect('test.db') - #sqlquery = 'INSERT INTO errorlogs (flodata, comments) VALUES ({},{})'.format( g.parsed_data['flodata'], errorform.comments.data) - #conn.execute(sqlquery) - print(g.parsed_data) - #conn.close() - return render_template('index.html', form=form, parsed_data= g.parsed_data, errorform=errorform) + conn = sqlite3.connect('test.db') + sqlquery = 'INSERT INTO errorlogs (flodata, comments) VALUES ({},{})'.format( g.parsed_data['flodata'], errorform.comments.data) + conn.execute(sqlquery) + conn.close() + return render_template('index.html', form=form, parsed_data= parsed_data, errorform=errorform) return render_template('index.html', form=form, errorform=errorform) app.run(debug=True) - diff --git a/errors.db b/errors.db deleted file mode 100644 index 6c82df4..0000000 Binary files a/errors.db and /dev/null differ diff --git a/flo.py b/flo.py deleted file mode 100644 index d9c6107..0000000 --- a/flo.py +++ /dev/null @@ -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')) \ No newline at end of file diff --git a/parse.py b/parse.py deleted file mode 100644 index 3970964..0000000 --- a/parse.py +++ /dev/null @@ -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''' diff --git a/parse-mod.py b/parse_flodata.py similarity index 54% rename from parse-mod.py rename to parse_flodata.py index 0a29b35..572737e 100644 --- a/parse-mod.py +++ b/parse_flodata.py @@ -1,35 +1,35 @@ import re -import testcases -marker=None -operation=None -address=None -amount=None +marker = None +operation = None +address = None +amount = None -def extractMarkers(text): - returnval = None - text = text.lower() - text = ' '.join(text.split()) - 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 isTransfer(text): + wordlist = ['transfer','send','give'] #keep everything lowercase + textList = text.split(' ') + for word in wordlist: + if word in textList: + return True + return False -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 returnval = None - text = text.lower() for operation in operationList: - operation = operation.lower() - count = count + text.count(operation) if count > 1: - return 'od' + return 'Too many' if count == 1 and (returnval is None): returnval = operation return returnval @@ -38,7 +38,6 @@ def extractOperation(text, operationList): def extractAmount(text): count = 0 returnval = None - text = text.lower() splitText = re.split("\W+", text) for word in splitText: @@ -51,21 +50,12 @@ def extractAmount(text): pass if count > 1: - return 'od' + return 'Too many' 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): - cleantext = re.sub(' +', ' ',text) - textList = cleantext.split(' ') +def extractMarker(text): + textList = text.split(' ') for word in textList: if word[-1] == '#': return word @@ -73,8 +63,7 @@ def extractIncMarker(text): def extractInitTokens(text): base_units = {'thousand':10**3 , 'million':10**6 ,'billion':10**9, 'trillion':10**12} - cleantext = re.sub(' +', ' ',text) - textList = cleantext.split(' ') + textList = text.split(' ') for idx,word in enumerate(textList): try: result = float(word) @@ -84,19 +73,28 @@ def extractInitTokens(text): except: continue + # Combine test def parse_flodata(string): - if not isIncorp(string): - operationList = ['send', 'transfer', 'give'] - marker = extractMarkers(string) - operation = extractOperation(string, operationList) - amount = extractAmount(string) + if string[0:5] == 'text:': + string = string.split('text:')[1] + + cleanstring = re.sub(' +', ' ', 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, 'amount': amount} + elif isIncorp(cleanstring): + incMarker = extractMarker(cleanstring) + initTokens = extractAmount(cleanstring) + parsed_data = {'type': 'incorporation', 'flodata': string, 'marker': incMarker, 'initTokens': initTokens} else: - incMarker = extractIncMarker(string) - initTokens = extractInitTokens(string) - parsed_data = {'type': 'incorporation', 'flodata': string, 'marker': marker, 'initTokens': initTokens} + parsed_data = {'type': 'noise'} + return parsed_data diff --git a/parse_incorp.py b/parse_incorp.py deleted file mode 100644 index f62d6ef..0000000 --- a/parse_incorp.py +++ /dev/null @@ -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 - - - diff --git a/test.db b/test.db deleted file mode 100644 index e69de29..0000000