def spell_check(): form = SpellForm() if form.validate_on_submit(): original = form.spell.data result = get_shell_script_output_using_check_output(original) new_query = Qqquery(data=original, user_id=current_user.id, output=result) db.session.add(new_query) db.session.commit() flash('Success spell check') return redirect(url_for('index')) result = "no results" return render_template('spell_check.html', title='Spell Check', form=form, spell=result)
def spellcheck(): form = SpellForm() currUser = current_user.uname if form.validate_on_submit(): inputtext = form.inputtext.data with open('userinput.txt', 'w') as file: file.write(form.inputtext.data) file.close() textoutput = subprocess.run(['./a.out', 'userinput.txt', 'wordlist.txt'], stdout=subprocess.PIPE, check=True, universal_newlines=True) textmisspell = textoutput.stdout.replace("\n", ", ")[:-2] if textmisspell == "": textmisspell = "No words were misspelled." entry = Spell(uname=currUser, query_text=inputtext, query_results=textmisspell) db.session.add(entry) db.session.commit() return render_template('spell_check.html', textoutput=textoutput.stdout, textmisspell=textmisspell, form=form) return render_template('spell_check.html', form=form)
def spell(): """ route for authenticated users to input text for spell-checking """ form = SpellForm(request.form) result = "" text = "" if form.validate_on_submit(): text = form.inputtext.data # since the spell_check binary requires input text to be written to file # we keep a input.txt file that we can clear the contents and write the # new text to be checked for each submission with open(r"./app/input.txt", "r+") as f: f.truncate(0) f.write(text) # subprocess allows us to run the binary spell_check file from our submodule result = subprocess.check_output([ # location of the spell_check binary r"./app/lib/a.out", # r"./app/lib/spell_check", # location of the input.txt file that we just wrote the input to r"./app/input.txt", # location of the dictionary file to check the text against r"./app/lib/wordlist.txt", ]) # decode the returned text so that we can read it nicely result = result.decode("utf-8").strip() # clear after use so as to not leave clues around about what people are # searching for with open(r"./app/input.txt", "r+") as f: f.truncate(0) # persist the user's question q = Question(text=text, result=result, user_id=current_user.id) db.session.add(q) db.session.commit() flash("success", "success") else: flash_errors(form, category="result") return render_template("spell/index.html", form=form, orig_text=text, result=result)
def index(): # form = ListForm() # spells = db.session.query(Spell).all() # spell_list = [(i.spells, i.sname) for i in spells] form = SpellForm() if request.method == 'POST' and form.validate_on_submit(): spell = Spell(sname=form.sname.data, slevel=form.slevel.data, verbal=form.verbal.data, somatic=form.somatic.data, material=form.material.data, concentration=form.concentration.data, ritual=form.ritual.data, description=form.description.data) db.session.add(spell) db.session.commit() return redirect(url_for('index')) spells = Spell.query.all() return render_template("home.html", title='Main', form=form, spells=spells)
def spellcheck(): form = SpellForm() if form.validate_on_submit(): inputtext = form.inputtext.data with open('userinput.txt', 'w') as file: file.write(form.inputtext.data) file.close() textoutput = subprocess.run( ['./a.out', 'userinput.txt', 'wordlist.txt'], stdout=subprocess.PIPE, check=True, universal_newlines=True) textmisspell = textoutput.stdout.replace("\n", ", ")[:-2] if textmisspell == "": textmisspell = "No words found to be misspelled." return render_template('spell_check.html', textoutput=textoutput.stdout, textmisspell=textmisspell, form=form) return render_template('spellcheck.html', form=form)
def spell(): form = SpellForm() if form.validate_on_submit(): temptext = form.inputtext.data with open('userinput.txt', 'w') as file: file.write(temptext) file.close() textmisspell = subprocess.run( ['./a.out', 'userinput.txt', 'wordlist.txt'], stdout=subprocess.PIPE, check=True, universal_newlines=True) textoutput = (textmisspell.stdout).replace("\n", ",").strip().strip(',') #if textoutput == "": #textoutput = "No words were misspelled." return render_template('spellcheck.html', misspelled=textoutput, textout=temptext, form=form) else: #return render_template('spellcheck.html', misspelled=textoutput, textout=temptext, form=form) return render_template('spellcheck.html', form=form)