From ae75366417b9f3d1d5120a62b7b1ead1c713da4e Mon Sep 17 00:00:00 2001 From: Harshal Chaudhari Date: Mon, 27 Mar 2023 23:11:32 +0100 Subject: [PATCH] docs(example.py): demonstration file for working with handlers Signed-off-by: Harshal Chaudhari --- example.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 example.py diff --git a/example.py b/example.py new file mode 100644 index 0000000..d4e00e4 --- /dev/null +++ b/example.py @@ -0,0 +1,43 @@ + +from yapyfuzz.core import Fuzzy +from yapyfuzz.handler import ListHandler, SQLiteHandler, PostgresHandler +import os + +root_dir = os.path.abspath(__file__) + +terms = ["hello", "world", "foo", "bar"] +list_handler = ListHandler() +list_handler.reader(terms) + +name = f"{root_dir}/yapy/fuzzy.db" +query = "select * from albums" +db_handler = SQLiteHandler() +db_handler.reader(name, query) + +db_settings = { + "user":"postgres", + "password":"postgres", + "host":"localhost", + "port":"5432", + "dbname":"dellstore", +} + +pg_handler = PostgresHandler() +# pg_handler.reader(query="select table_schema, table_name from information_schema.tables") +pg_handler.reader(query="select * from categories", **db_settings) +pg_handler.reader(query="select * from inventory", **db_settings) + +fp = Fuzzy(pg_handler) +fp.get_selection() + +fp = Fuzzy(list_handler) +fp.get_selection() + +fp = Fuzzy(db_handler) +fp.get_selection() + + +# output = os.popen( +# "sqlite3 /home/harshal/Works/oss_projects/pyfuzzy/pyfuzzy/fuzzy.db \"select * from albums\"" +# ).read().encode("utf-8") +# type(output) \ No newline at end of file