From 78633551f66783cb21886aada9b89acedcef2b4e Mon Sep 17 00:00:00 2001 From: Vivek Teega Date: Fri, 15 Feb 2019 16:35:51 +0530 Subject: [PATCH] First commit --- .gitignore | 2 + app.py | 44 ++++++++++++++++ errors.db | Bin 0 -> 12288 bytes flo.py | 17 ++++++ parse-mod.py | 102 ++++++++++++++++++++++++++++++++++++ parse.py | 121 +++++++++++++++++++++++++++++++++++++++++++ parse_incorp.py | 111 +++++++++++++++++++++++++++++++++++++++ templates/index.html | 41 +++++++++++++++ test.db | 0 testcases.py | 15 ++++++ testcases.pyc | Bin 0 -> 662 bytes 11 files changed, 453 insertions(+) create mode 100644 .gitignore create mode 100644 app.py create mode 100644 errors.db create mode 100644 flo.py create mode 100644 parse-mod.py create mode 100644 parse.py create mode 100644 parse_incorp.py create mode 100644 templates/index.html create mode 100644 test.db create mode 100644 testcases.py create mode 100644 testcases.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2483976 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +__pycache__/ diff --git a/app.py b/app.py new file mode 100644 index 0000000..9023dd3 --- /dev/null +++ b/app.py @@ -0,0 +1,44 @@ +from flask import Flask +from flask import render_template, flash, redirect, g +from flask_wtf import Form +from wtforms import StringField +from wtforms.validators import DataRequired +from wtforms.widgets import TextArea +import parse_incorp +import sqlite3 + +class MyForm(Form): + flodata = StringField('FLO Data', validators=[DataRequired()]) + +class ReportError(Form): + comments = StringField('Comments', widget=TextArea()) + +conn = sqlite3.connect('errors.db') +conn.execute('''CREATE TABLE IF NOT EXISTS errorlogs (id INTEGER PRIMARY KEY AUTOINCREMENT, flodata TEXT, comments TEXT);''') +conn.close() + +app = Flask(__name__) +app.config['SECRET_KEY'] = 'Teega' + + +@app.route("/", methods=['GET', 'POST']) +def textparse(): + form = MyForm() + 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) + + 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) + + return render_template('index.html', form=form, errorform=errorform) + +app.run(debug=True) + diff --git a/errors.db b/errors.db new file mode 100644 index 0000000000000000000000000000000000000000..6c82df41a0b03201fd3a0d4716c24be179e873e7 GIT binary patch literal 12288 zcmeI#KTE?v7{~FuRCJQMbrJfEEiEp614cQd*v1+om`P%Ll|uf|Bo2-az8_zrmtqTc zakhLPxa5A}?jWC=o`?I%sQY20rQK+`v8^T_ZG(F^`LELI;{5B> zt@7F<)&6u33IPNVKmY**5I_I{1Q0*~f&U>e^Nu@%fsX6sCAHN$b^Y^mW!G;upYO-k zb!hy^NaSBljO?xL3H9<6#Wm+tfI+4gcxil}b%;t5qiT$QGcTGQq00IagfB*sr pAb1: + 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) + 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} + 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 res + 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) + 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': marker, 'initTokens': initTokens} + + return parsed_data diff --git a/parse.py b/parse.py new file mode 100644 index 0000000..3970964 --- /dev/null +++ b/parse.py @@ -0,0 +1,121 @@ +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_incorp.py b/parse_incorp.py new file mode 100644 index 0000000..f62d6ef --- /dev/null +++ b/parse_incorp.py @@ -0,0 +1,111 @@ +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/templates/index.html b/templates/index.html new file mode 100644 index 0000000..8d30300 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,41 @@ + + + +

Incorporation and Transfer comment tester

+
+ {{ form.hidden_tag() }} +

+ Enter FLO data:
+ {{ form.flodata(size=80) }}
+

+

+
+ +{% if parsed_data %} + {% if parsed_data['type'] == 'transfer' %} +

type : {{ parsed_data['type'] }}

+

flodata : {{ parsed_data['flodata'] }}

+

marker : {{ parsed_data['marker'] }}

+

operation : {{ parsed_data['operation'] }}

+

amount : {{ parsed_data['amount'] }}

+ {% endif %} + {% if parsed_data['type'] == 'incorporation' %} +

type : {{ parsed_data['type'] }}

+

flodata : {{ parsed_data['flodata'] }}

+

marker : {{ parsed_data['marker'] }}

+

initTokens : {{ parsed_data['initTokens'] }}

+ {% endif %} +{% endif %} +------------------ +
+ {{ form.hidden_tag() }} + Ps - If you find an anamoly, please report the error below +

+ Comments on the error:
+ {{ errorform.comments(cols="35", rows="10") }}
+

+

+
+ + + diff --git a/test.db b/test.db new file mode 100644 index 0000000..e69de29 diff --git a/testcases.py b/testcases.py new file mode 100644 index 0000000..586acd8 --- /dev/null +++ b/testcases.py @@ -0,0 +1,15 @@ +testStrings = [ + 'create 21000000 tokens with token transfer marker being rmt#', + 'start 21 thousand coins with token transfer marker being rohit#', + 'incorporate 10 billion coins with marker being vivek#', + 'create 100 coins with marker being abc#', + 'start 10 tokens pqr#', + '100000 mnq#', + 'start 100000 mnq#', + 'mnq# start 10 billion', + 'mnq# start 10 crore', + 'create 2 crore tokens with marker being lnq#' + ] + + + diff --git a/testcases.pyc b/testcases.pyc new file mode 100644 index 0000000000000000000000000000000000000000..215469445de0976d5e68f23f7791fafa2fd81979 GIT binary patch literal 662 zcmZ`$OHYG95FUz;+FCI_4?aTD3kM_7NW2*1!D~IVO-zgzWL8RApkY>`f6u?ZV z3N(?&EIZ$R-#0VZKZD-)^Yk@>>T-B};FoSWAU_sh2havw16&8(0Ne!Z0&W5J0Q-R3 zfCIoCh#h$0^A1eBT_teHAx=u+27xQ{xyXnYH++leh!I(Y8NG`_CF&D&-h`M~q;j~z zR=OlItXW3)*dUtK7FL+4W;~i2VO`ID)3l=T89Hg^wI)}j$WNszkGNgV#4E-*95M@^|$hgP@W5