Browse Source

zero-zero-version

Francesco 2 years ago
commit
5cd9310c9e

+ 3 - 0
flask_be/.gitignore

@@ -0,0 +1,3 @@
+__pycache__/*
+.vscode/*
+venv/*

+ 28 - 0
flask_be/app.py

@@ -0,0 +1,28 @@
+from flask import Flask, request
+from flask_cors import CORS
+
+from engine.simple_query import doSimpleQuery
+
+app = Flask(__name__)
+CORS(app) # This will enable CORS for all routes
+
+@app.route('/simple_get_query', methods=['POST'])
+def simpleQuery():
+
+    appath = app.root_path
+
+    try:        
+        data = request.form['word']
+        output = doSimpleQuery(data, appath)
+
+        return output, 200
+
+    except:
+        emptyOut = {}
+        return emptyOut, 500
+
+if __name__ == '__main__':
+    app.run()
+
+
+

BIN
flask_be/db/test_x.db


+ 0 - 0
flask_be/engine/__init__.py


BIN
flask_be/engine/__pycache__/__init__.cpython-310.pyc


BIN
flask_be/engine/__pycache__/simple_query.cpython-310.pyc


+ 13 - 0
flask_be/engine/simple_query.py

@@ -0,0 +1,13 @@
+import sqlite3
+
+def doSimpleQuery(data, path):
+
+    theSimpleQuery = "SELECT norm FROM form WHERE norm LIKE '" + data + "'"
+
+    con = sqlite3.connect(path + "/db/test_x.db")
+    cur = con.cursor()
+
+    queryReponse = cur.execute(theSimpleQuery)
+    results = queryReponse.fetchall()
+
+    return results

+ 25 - 0
flask_be/engine/simple_query_test.py

@@ -0,0 +1,25 @@
+# %%
+# Test code using Jupyter
+
+# %%
+import sqlite3
+
+def doSimpleQuery(data, path):
+
+    print(path)
+    print(data)
+
+    theSimpleQuery = "SELECT norm FROM form WHERE norm LIKE '" + data + "'"
+
+    print(theSimpleQuery)
+
+    con = sqlite3.connect(path + "/db/test_x.db")
+    cur = con.cursor()
+
+    queryReponse = cur.execute(theSimpleQuery)
+    results = queryReponse.fetchall()
+
+    return results
+# %%
+doSimpleQuery("sor%", "../")
+# %%

+ 27 - 0
site/index.html

@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+  <meta charset="UTF-8">
+</head>
+
+
+<body>
+
+  <form id="simple_query">
+    <div>
+      Enter a word to search<br/>
+      <input type="text" id="query_text">
+    </div>
+  </form>
+
+  <span id="result"></span>
+
+
+  <!-- Javascript includes -->
+  <script src="vendor/jquery/jquery.min.js"></script>
+  <script src="index.js"></script>
+
+</body>
+
+</html>

+ 30 - 0
site/index.js

@@ -0,0 +1,30 @@
+
+// Executed when the page's DOM is loaded (at least in theory...)
+$(function(){
+
+    $('#simple_query').submit(
+        function (e) {
+            
+            e.preventDefault();
+
+            let f = $(this);
+
+            let word = f.find('[id=query_text]').val();
+            console.log(word)
+
+            let postData = {
+                word: word
+            }
+            $.post('http://127.0.0.1:5000/simple_get_query', postData,
+                function(results){
+                    console.log(results)
+                    if(results.length==0){
+                        alert('No results!')
+                    }
+                    $("#result").html(results.join('<br/>'));
+                }    
+            );
+           
+        }
+    )
+});

File diff suppressed because it is too large
+ 1 - 0
site/vendor/jquery/jquery.min.js


Some files were not shown because too many files changed in this diff