-
Notifications
You must be signed in to change notification settings - Fork 4
/
searchKeyword.py
30 lines (23 loc) · 901 Bytes
/
searchKeyword.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
import sqlite3
# Define database name and keywords
database_name = "contracts_merged_index.db"
keywords = ["lastTimeRewardApplicable", "rewardPerTokenStored"]
# Connect to the SQLite database
conn = sqlite3.connect(database_name)
cursor = conn.cursor()
# Build the query dynamically for multiple keywords
placeholders = " OR ".join(["content LIKE ?" for _ in keywords])
query = f"SELECT name, path FROM file_index WHERE {placeholders}"
# Execute the query with the keywords
cursor.execute(query, [f"%{kw}%" for kw in keywords])
# Fetch all matching results
results = cursor.fetchall()
# Print the name and path if matches are found
if results:
print(f"Entries containing keywords {', '.join(keywords)}:")
for name, path in results:
print(f"Name: {name}, Path: {path}")
else:
print(f"No entries found for keywords: {', '.join(keywords)}")
# Close the connection
conn.close()