-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
65 lines (55 loc) · 2.11 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sqlite3
import os
import json
from os.path import join, dirname
from dotenv import load_dotenv
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
db_name = os.getenv("GEN_AI_MAP_DB_NAME", "ai-tools.db")
db_name = join(dirname(__file__), db_name)
# Function run query
def _run_query(query):
con = sqlite3.connect(db_name)
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute(query)
results = []
for r in cur.fetchall():
results.append(dict(r))
con.close()
return json.dumps(results)
# Function get Gen AI tool by name
def get_ai_tool_by_name(name):
return _run_query(f"SELECT * FROM ai_tools WHERE name='{name}' COLLATE NOCASE")
# Function to Get the list of AI tools from the SQLite database
def get_all_ai_tools_records():
return _run_query("SELECT * FROM ai_tools order by name")
# function to insert a new tool into te DB
def insert_ai_tool(name, link, ecosystem, category, enterprise_categories, license, description):
sql = '''INSERT INTO ai_tools (name, link, ecosystem, category, enterprise_categories, license, description, last_search) VALUES (? , ? , ? , ? , ? , ? , ? , datetime() )'''
fields = (name, link, ecosystem, category, enterprise_categories, license, description)
con = sqlite3.connect(db_name)
cur = con.cursor()
cur.execute(sql, fields)
con.commit()
con.close()
return True
# Function for update airtable records
def update_ai_tool_record(id, name, link, ecosystem, category, enterprise_categories, license, description):
sql = '''UPDATE ai_tools
SET name = ? ,
link = ? ,
ecosystem = ? ,
category = ? ,
enterprise_categories = ?
license = ? ,
description = ? ,
last_search = datetime()
WHERE id = ?'''
fields = (name, link, ecosystem, category, enterprise_categories, license, description, id)
con = sqlite3.connect(db_name)
cur = con.cursor()
cur.execute(sql, fields)
con.commit()
con.close()
return True